home *** CD-ROM | disk | FTP | other *** search
Java Source | 1996-06-13 | 2.2 KB | 94 lines |
- // SimpleComponent - demonstrates how to attach simple
- // Abstract Window Toolkit components
- // to an applet
-
- import java.applet.*;
- import java.awt.*;
-
- public class SimpleComponent extends Applet
- {
-
- // Label - a label is a string of text that can be
- // modified by the program but not by
- // the user
- private Label m_label = new Label("Type in the text field");
-
- // TextField - a text field represents a one-line
- // optionally editable area of text
- private TextField m_textField = new TextField(10);
-
- // Button - a button is a simple object that you can
- // select using the mouse or by tabbing to it
- // and pressing Enter
- private Button m_button = new Button("Read Text Field");
-
- public SimpleComponent()
- {
- // TODO: Add Constructor code here
- }
-
- public String getAppletInfo()
- {
- return "Name: SimpleComponent\r\n" +
- "Author: Stephan R. Davis\r\n" +
- "Created for Learn Java Now";
- }
-
-
- public void init()
- {
- resize(320, 240);
-
- // TODO: Place Addition Initialization code here
- // Attach the label, text field, and button to the
- // applet
- add(m_label);
- add(m_textField);
- add(m_button);
- }
-
- public void destroy()
- {
- // TODO: Place applet cleanup code here
- }
-
- public void paint(Graphics g)
- {
- }
-
- public boolean action(Event event, Object obj)
- {
- // if this action sprung from a button...
- Object oTarget = event.target;
- if (oTarget instanceof Button)
- {
- // ...and if the button label is the same
- // as "our button"
- Button buttonTarget = (Button)oTarget;
- String sButtonString = buttonTarget.getLabel();
- if (sButtonString.compareTo("Read Text Field") == 0)
- {
- String s = m_textField.getText();
- m_label.setText(s);
- return true;
- }
- }
- return false;
- }
-
- public void start()
- {
- // TODO: Place additional applet Start code here
- }
-
- public void stop()
- {
- }
-
-
-
-
- // TODO: Place additional applet Code here
-
- }
-