home *** CD-ROM | disk | FTP | other *** search
/ Java by Example / jbecd.bin / JBE-CD / NTUsers / JBECODE.ZIP / JavaByExample / chap18 / ButtonApplet.java < prev    next >
Text File  |  1996-02-23  |  1KB  |  44 lines

  1. import java.awt.*;
  2. import java.applet.*;
  3.  
  4. public class ButtonApplet extends Applet
  5. {
  6.     Button button1;
  7.     Button button2;
  8.     Button button3;
  9.  
  10.     public void init()
  11.     {
  12.         button1 = new Button("Button1");
  13.         button2 = new Button("Button2");
  14.         button3 = new Button("Button3");
  15.  
  16.         add(button1);
  17.         add(button2);
  18.         add(button3);
  19.     }
  20.  
  21.     public boolean action(Event evt, Object arg)
  22.     {
  23.         if (evt.target instanceof Button)
  24.             HandleButtons(arg);
  25.         return true;
  26.     }
  27.  
  28.     protected void HandleButtons(Object label)
  29.     {
  30.         if (label == "Button1")
  31.             button1.setLabel("1nottuB");
  32.         else if (label == "Button2")
  33.             button2.setLabel("2nottuB");
  34.         else if (label == "Button3")
  35.             button3.setLabel("3nottuB");
  36.         else
  37.         {
  38.             button1.setLabel("Button1");
  39.             button2.setLabel("Button2");
  40.             button3.setLabel("Button3");
  41.         }
  42.     }
  43. }
  44.