home *** CD-ROM | disk | FTP | other *** search
/ Learn Java Now / Learn_Java_Now_Microsoft_1996.iso / JavaNow / Code / Chap17 / SimpleComponent / SimpleComponent.class (.txt) next >
Encoding:
Java Class File  |  1996-07-29  |  2.1 KB  |  52 lines

  1. import java.applet.Applet;
  2. import java.awt.Button;
  3. import java.awt.Container;
  4. import java.awt.Event;
  5. import java.awt.Graphics;
  6. import java.awt.Label;
  7. import java.awt.TextField;
  8.  
  9. public class SimpleComponent extends Applet {
  10.    private Label m_label = new Label("Type in the text field");
  11.    private TextField m_textField = new TextField(10);
  12.    private Button m_button = new Button("Read Text Field");
  13.  
  14.    public void start() {
  15.    }
  16.  
  17.    public void stop() {
  18.    }
  19.  
  20.    public String getAppletInfo() {
  21.       return "Name: SimpleComponent\r\n" + "Author: Stephan R. Davis\r\n" + "Created for Learn Java Now";
  22.    }
  23.  
  24.    public boolean action(Event event, Object obj) {
  25.       Object oTarget = event.target;
  26.       if (oTarget instanceof Button) {
  27.          Button buttonTarget = (Button)oTarget;
  28.          String sButtonString = buttonTarget.getLabel();
  29.          if (sButtonString.compareTo("Read Text Field") == 0) {
  30.             String s = this.m_textField.getText();
  31.             this.m_label.setText(s);
  32.             return true;
  33.          }
  34.       }
  35.  
  36.       return false;
  37.    }
  38.  
  39.    public void destroy() {
  40.    }
  41.  
  42.    public void init() {
  43.       ((Applet)this).resize(320, 240);
  44.       ((Container)this).add(this.m_label);
  45.       ((Container)this).add(this.m_textField);
  46.       ((Container)this).add(this.m_button);
  47.    }
  48.  
  49.    public void paint(Graphics g) {
  50.    }
  51. }
  52.