home *** CD-ROM | disk | FTP | other *** search
/ Java by Example / jbecd.bin / JBE-CD / NTUsers / JBECODE.ZIP / JavaByExample / chap19 / EchoApplet.java < prev    next >
Encoding:
Java Source  |  1996-02-26  |  828 b   |  40 lines

  1. import java.awt.*;
  2. import java.applet.*;
  3.  
  4. public class EchoApplet extends Applet
  5. {
  6.     TextField textField;
  7.     Button button;
  8.  
  9.     public void init()
  10.     {
  11.         textField = new TextField("", 25);
  12.         button = new Button("Change Echo");
  13.  
  14.         textField.setEchoCharacter('*');
  15.  
  16.         add(textField);
  17.         add(button);
  18.     }
  19.  
  20.     public boolean action(Event evt, Object arg)
  21.     {
  22.         if (evt.target instanceof Button)
  23.             ChangeEcho();
  24.  
  25.         return true;
  26.     }
  27.  
  28.     protected void ChangeEcho()
  29.     {
  30.         char c = textField.getEchoChar();
  31.  
  32.         if (c == '*')
  33.             textField.setEchoCharacter('#');
  34.         else if (c == '#')
  35.             textField.setEchoCharacter('$');
  36.         else
  37.             textField.setEchoCharacter('*');            
  38.     }
  39. }
  40.