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

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