home *** CD-ROM | disk | FTP | other *** search
Java Source | 1996-06-13 | 2.7 KB | 105 lines |
- // SimpleComponent - demonstrates how to attach simple
- // Abstract Window Toolkit components
- // to an applet using a Border Layout
-
- 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
- // Use a BorderLayout manager
- setLayout(new BorderLayout());
-
- // create a panel with the label and text together
- // (put the label above the text field - using Center
- // for the text field gives it any remaining room
- // after the label takes its cut)
- Panel panelText = new Panel();
- panelText.setLayout(new BorderLayout());
- panelText.add("North", m_label);
- panelText.add("Center", m_textField);
-
- // now add the panel to the applet on the left and
- // the button on the right
- add("Center", panelText);
- add("East", 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
-
- }
-