FileDocCategorySizeDatePackage
TextEventDemo.javaAPI DocExample3202Tue Dec 12 18:58:50 GMT 2000None

TextEventDemo

public class TextEventDemo extends Applet implements ActionListener

Fields Summary
TextField
textField
TextArea
textArea
TextArea
displayArea
Constructors Summary
Methods Summary
public voidactionPerformed(java.awt.event.ActionEvent e)
Handle button click.

        displayArea.setText("");
        textField.requestFocus();
    
public voidinit()

        Button button = new Button("Clear");
        button.addActionListener(this);

        textField = new TextField(20);
        textField.addActionListener(new MyTextActionListener());
        textField.addTextListener(new MyTextListener("Text Field"));

        textArea = new TextArea(5, 20);
        textArea.addTextListener(new MyTextListener("Text Area"));

        displayArea = new TextArea(5, 20);
        displayArea.setEditable(false);

        GridBagLayout gridbag = new GridBagLayout();
        GridBagConstraints c = new GridBagConstraints();
        setLayout(gridbag);
        c.fill = GridBagConstraints.BOTH;
        c.weightx = 1.0;

        /*
         * Hack to get around gridbag's refusal to allow
         * multi-row components in anything but the left column.
         */
        Panel leftPanel = new Panel();
        leftPanel.setLayout(new BorderLayout());
        leftPanel.add("North", textField);
        leftPanel.add("Center", textArea);

        c.gridheight = 2;
        gridbag.setConstraints(leftPanel, c);
        add(leftPanel);

        c.weighty = 1.0;
        c.gridwidth = GridBagConstraints.REMAINDER;
        c.gridheight = 1;
        gridbag.setConstraints(displayArea, c);
        add(displayArea);

        c.weighty = 0.0;
        gridbag.setConstraints(button, c);
        add(button);

        textField.requestFocus();