home *** CD-ROM | disk | FTP | other *** search
/ Java by Example / jbecd.bin / JBE-CD / NTUsers / JBECODE.ZIP / JavaByExample / chap14 / Applet19.java < prev    next >
Text File  |  1996-02-16  |  845b  |  36 lines

  1. import java.awt.*;
  2. import java.applet.*;
  3. import MyClass;
  4.  
  5. public class Applet19 extends Applet
  6. {
  7.     MyClass myObject;
  8.     TextField textField1;
  9.  
  10.     public void init()
  11.     {
  12.         myObject = new MyClass(1);
  13.         textField1 = new TextField(10);
  14.         add(textField1);
  15.         textField1.setText("1");
  16.     }
  17.  
  18.     public void paint(Graphics g)
  19.     {
  20.         String s = textField1.getText();
  21.         int value = Integer.parseInt(s);
  22.         myObject.SetField(value);
  23.         value = myObject.GetField();
  24.         s = String.valueOf(value);
  25.         g.drawString("The data field of the object", 30, 80);
  26.         g.drawString("is now set to this value:", 40, 95);
  27.         g.drawString(s, 90, 125);
  28.     }
  29.  
  30.     public boolean action(Event event, Object arg)
  31.     {
  32.         repaint();
  33.         return true;
  34.     }
  35. }
  36.