public class Login extends JFrame
1: import javax.swing.*;
2: import java.awt.*;
3: import java.awt.event.*;
4:
5: public class Login extends JFrame
6: implements ActionListener
7: {
8: public static final int WIDTH = 450;
9: public static final int HEIGHT = 200;
10:
11: private JTextField nameTextField, passTextField;
12:
13: public Login()
14: {
15: setTitle("Login Window");
16: setSize(WIDTH, HEIGHT);
17: addWindowListener(new WindowDestroyer());
18: Container contentPane = getContentPane();
19: contentPane.setLayout(new BorderLayout());
20:
21: JPanel userPanel = new JPanel();
22: userPanel.setLayout(new GridLayout(2,2));
23:
24: JLabel nameLabel = new JLabel("Enter your user name: ");
25: userPanel.add(nameLabel);
26: nameTextField = new JTextField(20);
27: userPanel.add(nameTextField);
28:
29: JLabel passLabel = new JLabel("Enter your password: ");
30: userPanel.add(passLabel);
31: passTextField = new JTextField(20);
32: userPanel.add(passTextField);
33:
34: contentPane.add(userPanel, BorderLayout.NORTH);
35:
36: JPanel buttonPanel = new JPanel();
37: buttonPanel.setLayout(new FlowLayout());
38:
39: JButton loginButton = new JButton("Login");
40: loginButton.addActionListener(this);
41: buttonPanel.add(loginButton);
42:
43: JButton exitButton = new JButton("Exit");
44: exitButton.addActionListener(this);
45: buttonPanel.add(exitButton);
46:
47: contentPane.add(buttonPanel, BorderLayout.SOUTH);
48: }
49:
50: public void actionPerformed(ActionEvent e)
51: {
52: if(e.getActionCommand().equals("Login"))
53: {
54: JOptionPane.showMessageDialog(null,
55: nameTextField.getText() + "\n" +
56: passTextField.getText());
57: }
58: else
59: {
60: System.exit(0);
61: }
62: }
63:
64: public static void main(String[] args)
65: {
66: Login gui = new Login();
67: gui.setVisible(true);
68: }
69: }