FileDocCategorySizeDatePackage
IntAlm2.javaAPI DocExample3692Tue May 08 13:45:28 BST 2001None

IntAlm2

public class IntAlm2 extends Applet implements ActionListener, ItemListener

Fields Summary
private Panel
displayP
private Panel
displayP2
private Panel
displayP3
private Label
labEC
private TextField
tf
private Button
okBut
private Button
but1
private Button
but2
private Button
but3
private Button
but4
private String
code
private final String
defaultCode
private String
userCode
private boolean
controlFlag
private CheckboxGroup
bGrp
private Checkbox
rBut1
private Checkbox
rBut2
private Checkbox
rBut3
Constructors Summary
public IntAlm2()

   
     
   
     setLayout(new BorderLayout( ));
   	topPanel( );
	add (displayP,BorderLayout.NORTH);
	midPanel( );
	add (displayP2,BorderLayout.CENTER);
	controlPanel( );  
   
Methods Summary
public voidactionPerformed(java.awt.event.ActionEvent ae)

	if(ae.getSource( ) == but1)
	{
	   code = code + "1";
	   tf.setText(code);
	}
	if(ae.getSource( ) == but2)
	{
	   code = code + "2";
	   tf.setText(code);
	}
	if(ae.getSource( ) == but3)
	{
	   code = code + "3";
	   tf.setText(code);
	}
	if(ae.getSource( ) == but4)
	{
	   code = code + "4";
	   tf.setText(code);
	}
	if(ae.getSource( ) == okBut)
	{
	   code = tf.getText( );
        if ((code.equals(defaultCode))||
                    (code.equals(userCode))||
                            (controlFlag == true))
	   {
	      if (rBut1.getState( ) == true)
	      {
	         userCode = code;
		    code = "";
		    waitaBit( );
		    tf.setText("New Code");
	         rBut3.setState(true);//switches off rBut1
		    waitaBit( );
	         disableController( );
		    tf.setText("");
	      }
	      else
	      {
		    enableController( );
	      }  				
	      if (rBut2.getState( ) == true)
	      {
	
	      }
	    }		
	  }
	
public voidcontrolPanel()

	displayP3 = new Panel( );
	bGrp = new CheckboxGroup( );
	rBut1 = new Checkbox("Change code", false, bGrp);
	rBut2 = new Checkbox("Disable alarm", false, bGrp);
	rBut3 = new Checkbox("Dummy", false, bGrp);
	rBut1.addItemListener(this);
	rBut2.addItemListener(this);
	displayP3.add(rBut1);
	displayP3.add(rBut2);
   
public voiddisableController()

	   displayP3.setVisible(false);
	   validate( );
	   controlFlag = false;
	
public voidenableController()

	   add (displayP3,BorderLayout.SOUTH);
	   displayP3.setVisible(true);
	   validate( );
	   controlFlag = true;
	
public voiditemStateChanged(java.awt.event.ItemEvent ie)

	   if (ie.getSource( ) == rBut1)
	   {
		tf.setText("");
		code = "";
	   }
	
public voidmidPanel()

	displayP2 = new Panel( );
	displayP2.setLayout(new FlowLayout( ));
     displayP2.setFont(new Font("SansSerif",
                                     Font.PLAIN,20));
	but1 = new Button("1");
	but2 = new Button("2");
	but3 = new Button("3");
	but4 = new Button("4");
	but1.addActionListener(this);
	but2.addActionListener(this);
	but3.addActionListener(this);
	but4.addActionListener(this);
     displayP2.add(but1);
	displayP2.add(but2);
	displayP2.add(but3);
	displayP2.add(but4);
   
public voidtopPanel()

	displayP = new Panel( );
	labEC = new Label("Enter Code: ");
	displayP.add(labEC);
	tf = new TextField(7);
	displayP.add(tf);
	okBut = new Button("OK");
	okBut.addActionListener(this);
	displayP.add(okBut);
   
public voidwaitaBit()

	   long timeInMis = System.currentTimeMillis( );
	   long t = 0;
	   do
	   {
		 t = t + 1;
   } while (System.currentTimeMillis( ) < timeInMis
    + 1000);