home *** CD-ROM | disk | FTP | other *** search
/ Chip 1998 July / Chip_1998-07_cd.bin / zkuste / JBuilder / BDK / Win / bdk_sep97.exe / _SETUP.1 / Flipper.java < prev    next >
Encoding:
Java Source  |  1997-09-10  |  1.2 KB  |  55 lines

  1.  
  2. package sunw.demo.transitional;
  3.  
  4. /**
  5.  * A very simple demo applet that uses the "OurButton" bean
  6.  * and the "TransitionalBean" bean.
  7.  *
  8.  * We ctach "ButtonPush" events from the button and then change the
  9.  * color on the target TransitionalBean.
  10.  */
  11.  
  12. import java.awt.Color;
  13.  
  14. public class Flipper extends java.applet.Applet implements ButtonPushListener {
  15.  
  16.     public void init() {
  17.  
  18.     // We do our own hand layout.
  19.     setLayout(null);
  20.  
  21.     // Create a TransitionalBean.
  22.     jb = new TransitionalBean();
  23.     jb.setColor(firstColor);
  24.     add(jb);
  25.     jb.reshape(250, 25, 100, 40);
  26.  
  27.     // Create a button.
  28.     btn = new OurButton();
  29.     btn.setLabel("flip");
  30.     add(btn);
  31.     btn.reshape(100, 30, 100, 30);
  32.  
  33.     // Add ourself as an event handler object for button pushes.
  34.     btn.addButtonPushListener(this);
  35.     }
  36.  
  37.     /**
  38.      * This methods catches a button push event and uses it to
  39.      * flip the color off our TransitionalBean between two choices.
  40.      */
  41.  
  42.     public void push(ButtonPushEvent evt) {
  43.     if (jb.getColor() == firstColor) {
  44.         jb.setColor(secondColor);
  45.     } else {
  46.         jb.setColor(firstColor);
  47.     }
  48.     }
  49.  
  50.     private Color firstColor = Color.green;
  51.     private Color secondColor = Color.blue;
  52.     private TransitionalBean jb;
  53.     private OurButton btn;
  54. }
  55.