Source of UsersApplet.java


  1: import javax.swing.*;
  2: import java.awt.*;
  3: import java.awt.event.*;
  4: 
  5: public class UsersApplet extends JApplet
  6:         implements ActionListener
  7: {
  8:         private JLabel userLabel;
  9:         private JLabel pwdLabel;
 10:         private JTextField userTextField;
 11:         private JTextField passwordTextField;
 12:         private JButton signinButton;
 13:         private JButton cancelButton;
 14: 
 15:         public void init()
 16:         {
 17:                 Container contentPane = getContentPane();
 18:                 contentPane.setLayout(new FlowLayout());
 19: 
 20:                 //User name components
 21:                 userLabel = new JLabel("User Name: ");
 22:                 contentPane.add(userLabel);
 23:                 userTextField = new JTextField(30);
 24:                 contentPane.add(userTextField);
 25: 
 26:                 //Password components
 27:                 pwdLabel = new JLabel("Password: ");
 28:                 contentPane.add(pwdLabel);
 29:                 passwordTextField = new JTextField(30);
 30:                 contentPane.add(passwordTextField);
 31: 
 32:                 //Buttons
 33:                 signinButton = new JButton("Sign In Now!");
 34:                 contentPane.add(signinButton);
 35:                 signinButton.addActionListener(this);
 36: 
 37:                 cancelButton = new JButton("Cancel");
 38:                 contentPane.add(cancelButton);
 39:                 cancelButton.addActionListener(this);
 40:         }
 41: 
 42:         public void actionPerformed(ActionEvent e)
 43:         {
 44:                 String actionCommand = e.getActionCommand();
 45: 
 46:                 if(actionCommand.equals("Sign In Now!"))
 47:                 {
 48:                         JOptionPane.showMessageDialog(null,
 49:                                 "User name " + userTextField.getText() +
 50:                                 "\nPassword " + passwordTextField.getText());
 51:                         userTextField.setText(" ");
 52:                         passwordTextField.setText(" ");
 53:                 }
 54:                 else if(actionCommand.equals("Cancel"))
 55:                 {
 56:                         userTextField.setText(" ");
 57:                         passwordTextField.setText(" ");
 58:                 }
 59:         }
 60: }