import java.awt.event.*; import java.awt.*; import Mailbox; /** * * * * * * * * @author Ashfaqur Rahman * @author Jared Baszler * @author Mike Yohay * @author Prashant Paroda * @version 1.0 of October 1999 */ public class GM extends WindowAdapter implements ActionListener { // +--------+-------------------------------------------------- // | Fields | // +--------+ /** The frame used for interaction. */ protected Frame login; /** The textfield in which the user enters a name. */ protected TextField userName; /** The textfield in which the password is entered. */ protected TextField password; /** The button the user presses. */ protected Button loginButton; /** The labels used to put comments and instructions in the screen. */ protected Label out, out1, out2, out3, out4; // +--------------+-------------------------------------------- // | Constructors | // +--------------+ /** Set up the frame for interaction. */ protected GM() { // Create the frame (the window). login = new Frame("GMAIL"); login.setBackground(Color.black); login.setForeground(Color.white); login.addWindowListener(this); userName = new TextField(20); password = new TextField(20); password.setEchoChar('*'); loginButton = new Button("Login"); loginButton.addActionListener(this); out = new Label("Please enter your Username and Password"); out1 = new Label("Username:"); out2 = new Label("Password:"); out3 = new Label("Welcome to GMAIL"); out4 = new Label("GMAIL"); GridBagLayout gridbag = new GridBagLayout(); login.setLayout(gridbag); GridBagConstraints c = new GridBagConstraints(); c.gridwidth = GridBagConstraints.REMAINDER; c.weightx = 0.1; c.weighty = 0.1; c.anchor = GridBagConstraints.NORTH; c.gridx = 0; c.gridy = 0; login.setFont(new Font("Times", Font.BOLD, 20)); out4.setFont(new Font("Times", Font.ITALIC, 60)); gridbag.setConstraints(out4, c); login.add(out4); c.gridx = 0; c.gridy = 1; out3.setFont(new Font("Times", Font.ITALIC, 40)); gridbag.setConstraints(out3, c); login.add(out3); c.gridx = 0; c.gridy = 2; gridbag.setConstraints(out, c); login.add(out); c.gridx = 0; c.gridy = 3; c.gridwidth = GridBagConstraints.RELATIVE; gridbag.setConstraints(out1, c); login.add(out1); userName.setBackground(Color.white); userName.setForeground(Color.black); c.gridx = 1; c.gridy = 3; gridbag.setConstraints(userName, c); login.add(userName); c.gridx = 0; c.gridy = 4; gridbag.setConstraints(out2, c); login.add(out2); password.setBackground(Color.white); password.setForeground(Color.black); c.gridx = 1; c.gridy = 4; gridbag.setConstraints(password, c); login.add(password); c.gridwidth = GridBagConstraints.REMAINDER; loginButton.setBackground(java.awt.Color.red); loginButton.setForeground(java.awt.Color.black); c.gridx = 0; c.gridy = 5; gridbag.setConstraints(loginButton, c); login.add(loginButton); login.pack(); login.setSize(700,800); login.show(); } // +---------+---------------------------------------------- // | Methods | // +---------+ // +----------------+------------------------------------------ // | Event Handlers | // +----------------+ /** React to a click on the button. */ public void actionPerformed(ActionEvent evt) { String command = evt.getActionCommand(); boolean loggedIn= true; if(command.equals("Login")) { try { Mailbox connection = new Mailbox(); connection.login(userName.getText(), password.getText()); } catch(Exception e) { loggedIn = false; login.dispose(); new GM1(); } if (loggedIn) { login.dispose(); new Folders(); } } } /** React to the closing of the window. */ public void windowClosing(WindowEvent event) { login.dispose(); System.exit(0); } // windowClosing() // +------+---------------------------------------------------- // | Main | // +------+ /* Start the ball rolling by creating an object. */ public static void main(String[] args) { new GM(); } // main(String[]) } // class GreetGUI