What follows is the code you requested...
public class LoginFrame extends JFrame {
JPanel contentPane;
JPanel jPanel1 = new JPanel();
JLabel jLabelUserName = new JLabel();
JLabel jLabelPassword = new JLabel();
JPasswordField jPasswordField = new JPasswordField();
JTextField jUserNameField = new JTextField();
JButton QuitButton = new JButton();
JPanel jPanel2 = new JPanel();
JButton SubmitButton = new JButton();
JPanel jPanel3 = new JPanel();
JPanel jPanel4 = new JPanel();
GridBagLayout gridBagLayout1 = new GridBagLayout();
GridBagLayout gridBagLayout2 = new GridBagLayout();
GridBagLayout gridBagLayout3 = new GridBagLayout();
GridBagLayout gridBagLayout4 = new GridBagLayout();
GridBagLayout gridBagLayout5 = new GridBagLayout();
private Object x = this;
boolean resizable = false;
boolean generateNotification90 = false;
boolean generateNotification91 = false;
boolean generateNotification92 = false;
/**Construct the frame*/
public LoginFrame() {
enableEvents(AWTEvent.WINDOW_EVENT_MASK);
try {
jbInit();
}
catch(Exception e) {
e.printStackTrace();
}
}
/**Component initialization*/
private void jbInit() throws Exception {
contentPane = (JPanel) this.getContentPane();
contentPane.setLayout(gridBagLayout1);
this.setSize(new Dimension(400, 300));
this.setResizable(resizable);
this.setTitle("Login");
jPanel1.setLayout(gridBagLayout2);
jLabelUserName.setToolTipText("");
jLabelUserName.setHorizontalAlignment(SwingConstants.CENTER);
jLabelUserName.setHorizontalTextPosition(SwingConstants.RIGHT);
jLabelUserName.setText("User Name");
jLabelPassword.setToolTipText("");
jLabelPassword.setHorizontalAlignment(SwingConstants.CENTER);
jLabelPassword.setHorizontalTextPosition(SwingConstants.CENTER);
jLabelPassword.setText("Password");
jPanel1.setToolTipText("");
QuitButton.setText("Exit");
QuitButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
QuitButton_actionPerformed(e);
}
});
QuitButton.addMouseListener(new MouseAdapter() {
public void mousePressed(MouseEvent e) {
QuitButton_mousePressed(e);
}
});
jPanel2.setLayout(gridBagLayout5);
SubmitButton.setText("Submit");
SubmitButton.setEnabled(true);
SubmitButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
submitButtonActivated();
}
});
SubmitButton.addMouseListener(new MouseAdapter() {
public void mousePressed(MouseEvent f) {
if (f.getID() == f.MOUSE_PRESSED) {
submitButtonActivated();
}
}
});
jPanel3.setLayout(gridBagLayout4);
jPanel4.setLayout(gridBagLayout3);
contentPane.add(jPanel1, new GridBagConstraints(0, 0, 1, 1, 1.0, 1.0
,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(36, 29, 0, 67), 0, 13));
jPanel1.add(jLabelUserName, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0
,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(40, 22, 0, 0), 18, 5));
jPanel1.add(jLabelPassword, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0
,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(37, 22, 13, 0), 22, 5));
jPanel1.add(jPasswordField, new GridBagConstraints(1, 1, 1, 1, 1.0, 0.0
,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(35, 18, 13, 1), 72, 3));
jPanel1.add(jUserNameField, new GridBagConstraints(1, 0, 1, 1, 1.0, 0.0
,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(40, 17, 0, 1), 119, 2));
contentPane.add(jPanel2, new GridBagConstraints(0, 1, 1, 1, 1.0, 1.0
,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(26, 61, 34, 67), 0, 5));
jPanel2.add(jPanel3, new GridBagConstraints(0, 0, 1, 1, 1.0, 1.0
,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(5, 0, 0, 0), 0, 0));
jPanel3.add(SubmitButton, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0
,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(17, 9, 16, 9), 0, 0));
jPanel2.add(jPanel4, new GridBagConstraints(1, 0, 1, 1, 1.0, 1.0
,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(5, 90, 0, 0), 0, 0));
jPanel4.add(QuitButton, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0
,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(16, 9, 17, 9), 16, 0));
}
/**Overridden so we can exit when window is closed*/
protected void processWindowEvent(WindowEvent e) {
super.processWindowEvent(e);
if (e.getID() == WindowEvent.WINDOW_CLOSING) {
System.exit(0);
}
}
void QuitButton_mousePressed(MouseEvent e) {
ConfirmationsAndNotifications confirm = new ConfirmationsAndNotifications(this, 8);
this.setEnabled(false);
}
void QuitButton_actionPerformed(ActionEvent e) {
ConfirmationsAndNotifications confirm = new ConfirmationsAndNotifications(this, 8);
this.setEnabled(false);
}
void submitButtonActivated() {
try {
//-----------Added to replace deprecated getText() method------------------
jUserNameField.selectAll();
jPasswordField.selectAll();
String userName = jUserNameField.getSelectedText();
String passWord = jPasswordField.getSelectedText();
//---------End Added to replace deprecated getText() method-------------------
if (userName == null | | passWord == null) {
if (userName == null && passWord != null) {
// generate window telling user to supply a username
ConfirmationsAndNotifications notification = new ConfirmationsAndNotifications(x, 90);
} else if (userName != null && passWord == null) {
// generate window telling user to supply a password
ConfirmationsAndNotifications notification = new ConfirmationsAndNotifications(x, 91);
} else {
// generate window telling user to supply both a username
// and a password
ConfirmationsAndNotifications notification = new ConfirmationsAndNotifications(x, 92);
}
}else if (userName.equals("pervigil") && passWord.equals("pervigil")) {
this.hide();
MainFrame f = new MainFrame(this); // create a new MainFrame object
MainFrame currentMainFrame = f;
if (!f.imageFileDoesNotExistOrNotFile) {
f.dispose();
f.setJMenuBar(currentMainFrame.mb); // add the MenuBar object to this instance of MainFrame
this.dispose();
if (f.getConnectionStatus()) {
f.dispose();
} else {
//Validate frames that have preset sizes
//Pack frames that have useful preferred size info, e.g. from their layout
if (com.pervigil.PingUI.packFrame) {
f.pack();
} else {
f.validate();
}
//Center the window
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
Dimension frameSize = f.getSize();
if (frameSize.height > screenSize.height) {
frameSize.height = screenSize.height;
}
if (frameSize.width > screenSize.width) {
frameSize.width = screenSize.width;
}
f.setLocation((screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2);
f.setVisible(true);
}
} else {
this.dispose();
}
} else {
System.exit(1);
} // end of if statment to check username and password fields text
} catch (Exception i) {
System.out.println("NullPointerException or ClassCastException occured during Submitbutton actionPerformed method" + i);
}
} // end of submitButtonActivated method
} // end of LoginFrame class