In: Computer Science
Need this in java .Create a simple login screen in java That lets people sign in to the emergency room. It needs to ask for name, social,and DOB. Once all the information is received it then display the info back to them if any info is is missing have the program prompt the user to re enter their information.
import java.awt.FlowLayout;
import java.awt.Label;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
public class LoginFrame extends JFrame {
Label userLbl,socialLbl,DobLbl;
JTextField userTxtFld,soFld,DobFld;
JButton btnSubmit,btnCancel;
public LoginFrame() {
userLbl = new
Label("Username");
socialLbl = new
Label("Social");
DobLbl=new Label("Dob");
userTxtFld = new
JTextField(20);
soFld = new JTextField(20);
DobFld=new JTextField(20);
btnSubmit = new
JButton("Submit");
btnCancel = new
JButton("Cancel");
this.setLayout(new
FlowLayout());
this.add(userLbl);
this.add(userTxtFld);
this.add(socialLbl);
this.add(soFld);
this.add(DobLbl);
this.add(DobFld);
this.add(btnSubmit);
this.add(btnCancel);
//event linking code
btnCancel.addActionListener(new
ActionListener() {
@Override
public void
actionPerformed(ActionEvent e) {
}
});
btnSubmit.addActionListener(new ActionListener() {
@Override
public void
actionPerformed(ActionEvent e) {
if(userTxtFld.getText().equals("") &&
soFld.getText().equals("") &&
DobFld.getText().equals(""))
{
JOptionPane.showMessageDialog(null, "Please fill the blank
fields","Error",JOptionPane.ERROR_MESSAGE);
}
else
{
new
LoggedInDemo(userTxtFld.getText());
}
}
});
}
public static void main(String[] args) {
JFrame login = new
LoginFrame();
login.setTitle("Login");
login.setSize(350, 250);
login.setLocation(100, 200);
login.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
login.setVisible(true);
}
/*@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method
stub
}*/
}
//To display the Info
LoggediinDemo.java
import java.awt.FlowLayout;
import javax.swing.JFrame;
import javax.swing.JLabel;
import sun.applet.Main;
public class LoggedInDemo extends JFrame{
String user;
public LoggedInDemo(String user) {
// TODO Auto-generated constructor
stub
this.user=user;
this.setLayout(new
FlowLayout());
JLabel l1=new JLabel();
l1.setName(user);
this.add(l1);
this.setVisible(true);
this.setTitle("Login");
this.setSize(350, 250);
this.setLocation(100, 200);
}
}