/******************************* * Name: Huy Nguyen * * Lab #2 * * Fall 1998, ICS 52 * ********************************/ // EA.java -- ICS 52 homework #2 -- Fall, 1998 import java.awt.*; import java.awt.event.*; import java.util.*; import java.io.*; import SAO.*; class LoginDialog extends Frame { EAFrame parentFrame; boolean cancelled; public LoginDialog(EAFrame parentFrame) { this.parentFrame = parentFrame; setLayout(null); setVisible(false); setSize(298,183); setResizable(false); setBackground(new Color(12632256)); lblUser = new Label("User Name:"); lblUser.setBounds(48,60,70,20); add(lblUser); lblPassword = new Label("Password:"); lblPassword.setBounds(48,84,70,20); add(lblPassword); txtUser = new TextField(); txtUser.setBounds(132,60,97,20); add(txtUser); txtPassword = new TextField(); txtPassword.setBounds(132,84,97,20); txtPassword.setEchoCharacter('*'); add(txtPassword); btnOK = new Button(); btnOK.setLabel("OK"); btnOK.setBounds(60,120,77,23); btnOK.setBackground(new Color(12632256)); btnOK.addActionListener( new ButtonListener()); add(btnOK); btnCancel = new Button(); btnCancel.setLabel("Cancel"); btnCancel.setBounds(144,120,77,23); btnCancel.setBackground(new Color(12632256)); btnCancel.addActionListener( new ButtonListener()); add(btnCancel); lblInstruction = new Label("Please Enter User Name and Password"); lblInstruction.setBounds(36,24,228,22); add(lblInstruction); this.addWindowListener( new MyWindowAdapter() ); cancelled = false; setVisible(true); } Label lblUser; Label lblPassword; TextField txtUser; TextField txtPassword; Button btnOK; Button btnCancel; Label lblInstruction; class MyWindowAdapter extends WindowAdapter { public void windowClosing(WindowEvent event) { dispose(); } } class ButtonListener implements ActionListener { public void actionPerformed(ActionEvent event) { Object object = event.getSource(); if (object == btnCancel) { cancelled = true; parentFrame.setMenuBar( new StartMenuBar(parentFrame)); LoginDialog.this.dispose(); } else if (txtPassword.equals("")) { Attention a = new Attention( parentFrame, true, "Password cannot be null", true); a.show(); return; } else if (txtUser.getText().equals( txtPassword.getText())) // or else { LoginDialog.this.dispose(); } else { Attention a = new Attention( parentFrame, true, "Incorrect password. Try again", true); a.show(); return; } } } boolean wasNotCancelled() { return !cancelled; } }