import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.applet.Applet;

public class KeypadPasscode extends Applet implements ActionListener
{
    //TO DO: Make the Keypad work
    //  Fix the actionPerformed.
    //  This can be done in 4 lines.

    JTextField screen;

    public void init ()
    {
	resize (160, 180);
	screen = new JTextField (10);

	JButton b7 = new JButton ("7");
	b7.setActionCommand ("7");
	b7.addActionListener (this);

	JButton b8 = new JButton ("8");
	b8.setActionCommand ("8");
	b8.addActionListener (this);

	JButton b9 = new JButton ("9");
	b9.setActionCommand ("9");
	b9.addActionListener (this);



	JButton b4 = new JButton ("4");
	b4.setActionCommand ("4");
	b4.addActionListener (this);

	JButton b5 = new JButton ("5");
	b5.setActionCommand ("5");
	b5.addActionListener (this);

	JButton b6 = new JButton ("6");
	b6.setActionCommand ("6");
	b6.addActionListener (this);




	JButton b1 = new JButton ("1");
	b1.setActionCommand ("1");
	b1.addActionListener (this);

	JButton b2 = new JButton ("2");
	b2.setActionCommand ("2");
	b2.addActionListener (this);

	JButton b3 = new JButton ("3");
	b3.setActionCommand ("3");
	b3.addActionListener (this);

	JButton b0 = new JButton ("0");
	b0.setActionCommand ("0");
	b0.addActionListener (this);


	JButton bCE = new JButton ("CE");
	bCE.setActionCommand ("clear");
	bCE.addActionListener (this);
	bCE.setBackground (Color.orange);

	JButton next = new JButton (">");
	next.setActionCommand ("enter");
	next.addActionListener (this);
	next.setBackground (Color.orange);

	JLabel spacer = new JLabel ("");
	spacer.setPreferredSize (new Dimension (190, 1));
	JLabel spacer2 = new JLabel ("");
	spacer2.setPreferredSize (new Dimension (190, 1));
	JLabel spacer3 = new JLabel ("");
	spacer3.setPreferredSize (new Dimension (190, 1));
	JLabel spacer4 = new JLabel ("");
	spacer4.setPreferredSize (new Dimension (190, 1));

	add (screen);
	add (spacer);
	add (b7);
	add (b8);
	add (b9);
	add (spacer2);
	add (b4);
	add (b5);
	add (b6);
	add (spacer3);
	add (b1);
	add (b2);
	add (b3);
	add (spacer4);
	add (b0);
	add (bCE);
	add (next);
    }


    public void actionPerformed (ActionEvent e)
    {

	if (e.getActionCommand ().equals ("clear"))
	{ //should clear the "screen" JTextField - one line of code

	}
	else if (e.getActionCommand ().equals ("enter"))
	{ //should print "Entrance permitted" in status bar
	    //    the valid code is 986532 - two lines of code
	}
	else
	{ //handles all of the other buttons
	    // should add their number to the screen JTextField - one line

	}
    }
}


