
/*
   This applet tests two custom components, MirrorLabel and StopWatch.
   It also tests the validate() method.  The user can click a button
   to change the text on the components in the applet.  Clicking
   another button will validate the applet.  This will cause components
   that have been invalidated to be resized.  The MirrorLabel is
   automatically invalidated when its text is changed.  For the
   StopWatch and Buttons, it might be platform-dependent.
*/

import java.awt.*;
import java.awt.event.*;
import java.applet.*;

public class ComponentTest extends Applet implements ActionListener {

   MirrorLabel greet;
   StopWatch timer;
   Button changeText, validate;

   public void init() {
       setBackground(Color.lightGray);
       greet = new MirrorLabel("PLEASE LET ME OUT!");
       greet.setBackground(Color.black);
       greet.setForeground(Color.red);
       greet.setFont( new Font("SansSerif", Font.BOLD, 30) );
       add(greet);
       
       timer = new StopWatch();
       timer.setBackground(Color.white);
       timer.setForeground(Color.blue);
       timer.setFont(new Font("Serif", Font.PLAIN, 20));
       add( timer );
       
       changeText = new Button("Change Text in this Applet");
       changeText.addActionListener(this);
       add(changeText);
       
       validate = new Button("Validate");
       validate.addActionListener(this);
       add(validate);
   }
   
   public void actionPerformed(ActionEvent evt) {
      Object source = evt.getSource();
      if (source == changeText) {
          if (greet.getText().equals("PLEASE LET ME OUT!"))
             greet.setText("Help!");
          else
             greet.setText("PLEASE LET ME OUT!");
          timer.setText("Please click me.");
          if (validate.getLabel().equals("Validate"))
             validate.setLabel("Do Validation");
          else
             validate.setLabel("Validate");
          if (changeText.getLabel().equals("Change"))
             changeText.setLabel("Change Text in this Applet");
          else
             changeText.setLabel("Change");
      }
      else if (source == validate) {
          validate();
      }
   }
   
}
