home *** CD-ROM | disk | FTP | other *** search
- import java.applet.Applet;
- import java.awt.BorderLayout;
- import java.awt.Button;
- import java.awt.Container;
- import java.awt.Event;
- import java.awt.Graphics;
- import java.awt.Label;
- import java.awt.Panel;
- import java.awt.TextField;
-
- public class SimpleComponent extends Applet {
- private Label m_label = new Label("Type in the text field");
- private TextField m_textField = new TextField(10);
- private Button m_button = new Button("Read Text Field");
-
- public void start() {
- }
-
- public void stop() {
- }
-
- public String getAppletInfo() {
- return "Name: SimpleComponent\r\n" + "Author: Stephan R. Davis\r\n" + "Created for Learn Java Now";
- }
-
- public boolean action(Event event, Object obj) {
- Object oTarget = event.target;
- if (oTarget instanceof Button) {
- Button buttonTarget = (Button)oTarget;
- String sButtonString = buttonTarget.getLabel();
- if (sButtonString.compareTo("Read Text Field") == 0) {
- String s = this.m_textField.getText();
- this.m_label.setText(s);
- return true;
- }
- }
-
- return false;
- }
-
- public void destroy() {
- }
-
- public void init() {
- ((Applet)this).resize(320, 240);
- ((Container)this).setLayout(new BorderLayout());
- Panel panelText = new Panel();
- ((Container)panelText).setLayout(new BorderLayout());
- ((Container)panelText).add("North", this.m_label);
- ((Container)panelText).add("Center", this.m_textField);
- ((Container)this).add("Center", panelText);
- ((Container)this).add("East", this.m_button);
- }
-
- public void paint(Graphics g) {
- }
- }
-