// TextDemo.java // JDK 1.1 version by Ian Chai // // Note: this reproduces the functionality of the old JDK 1.0 TextDemo // and is *different* from Sun's JDK 1.1 TextDemo, which is more // complicated. import java.awt.*; import java.awt.event.*; import java.applet.*; public class TextDemo extends Applet { TextField inArea; TextArea outArea; public void init() { inArea = new TextField(20); outArea = new TextArea(5, 20); outArea.setEditable(false); inArea.addActionListener(new FieldListener()); //Add Components to the Applet. GridBagLayout gridBag = new GridBagLayout(); setLayout(gridBag); GridBagConstraints c = new GridBagConstraints(); c.gridwidth = GridBagConstraints.REMAINDER; c.fill = GridBagConstraints.HORIZONTAL; gridBag.setConstraints(inArea, c); add(inArea); c.fill = GridBagConstraints.BOTH; c.weightx = 1.0; c.weighty = 1.0; gridBag.setConstraints(outArea, c); add(outArea); validate(); } // Each instance of this class listens to one of the TextFields. class FieldListener implements ActionListener { public void actionPerformed(ActionEvent e) { TextField f; try {f = (TextField)e.getSource();} catch (ClassCastException evt) { outArea.append("Error: source isn't a TextField!\n"); return; } outArea.append(f.getText()+"\n"); f.selectAll(); } } }