import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class Login extends JFrame
	implements ActionListener
{
	public static final int WIDTH = 450;
	public static final int HEIGHT = 200;

	private JTextField nameTextField, passTextField;

	public Login()
	{
		setTitle("Login Window");
		setSize(WIDTH, HEIGHT);
		addWindowListener(new WindowDestroyer());
		Container contentPane = getContentPane();
		contentPane.setLayout(new BorderLayout());

		JPanel userPanel = new JPanel();
		userPanel.setLayout(new GridLayout(2,2));

		JLabel nameLabel = new JLabel("Enter your user name: ");
		userPanel.add(nameLabel);
		nameTextField = new JTextField(20);
		userPanel.add(nameTextField);

		JLabel passLabel = new JLabel("Enter your password: ");
		userPanel.add(passLabel);
		passTextField = new JTextField(20);
		userPanel.add(passTextField);

		contentPane.add(userPanel, BorderLayout.NORTH);

		JPanel buttonPanel = new JPanel();
		buttonPanel.setLayout(new FlowLayout());

		JButton loginButton = new JButton("Login");
		loginButton.addActionListener(this);
		buttonPanel.add(loginButton);

		JButton exitButton = new JButton("Exit");
		exitButton.addActionListener(this);
		buttonPanel.add(exitButton);

		contentPane.add(buttonPanel, BorderLayout.SOUTH);
	}

	public void actionPerformed(ActionEvent e)
	{
		if(e.getActionCommand().equals("Login"))
		{
			JOptionPane.showMessageDialog(null,
				nameTextField.getText() + "\n" +
				passTextField.getText());
		}
		else
		{
			System.exit(0);
		}
	}

	public static void main(String[] args)
	{
		Login gui = new Login();
		gui.setVisible(true);
	}
}