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

  1. import java.awt.*;
  2. import java.applet.*;
  3. import TestSubClass;
  4.  
  5. public class ClassApplet extends Applet
  6. {
  7.     TestSubClass testSubObject;
  8.     TextField textField1;
  9.     TextField textField2;
  10.  
  11.     public void init()
  12.     {
  13.         testSubObject = new TestSubClass(1, "Default String");
  14.         textField1 = new TextField(25);
  15.         add(textField1);
  16.         textField1.setText("Default String");
  17.         textField2 = new TextField(5);
  18.         add(textField2);
  19.         textField2.setText("1");
  20.     }
  21.  
  22.     public void paint(Graphics g)
  23.     {
  24.         String s = textField1.getText();
  25.         testSubObject.SetData(s);
  26.         s = textField2.getText();
  27.         int value = Integer.parseInt(s);
  28.         testSubObject.SetData2(value);
  29.  
  30.         g.drawString("Enter a string for data1 in", 30, 80);
  31.         g.drawString("the first box and an integer", 30, 95);
  32.         g.drawString("for data2 in the second box.", 30, 110);
  33.         g.drawString("Here is the complete data string:", 25, 160);
  34.         s = testSubObject.CreateDataString();
  35.         g.drawString(s, 50, 180);
  36.     }
  37.  
  38.     public boolean action(Event event, Object arg)
  39.     {
  40.         repaint();
  41.         return true;
  42.     }
  43. }
  44.