// HabTextDemo.java // JDK 1.1/Habanero 2.0 version by Ian Chai // // Note: this is the Habanerization of Ian Chai's JDK 1.1 version of // TextDemo.java // // This version uses read/writeObject to serialize the hablet package TextDemo; // added for Habanero's convenience import java.awt.*; import java.awt.event.*; import java.applet.*; // imports added due to Habanerization import ncsa.habanero.Habanero; import ncsa.habanero.*; import ncsa.habanero.streams.*; import java.io.IOException; public class HabTextDemo extends Hablet // change Applet to Hablet { 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();} try {f = (TextField)Habanero.getSource();} // change getSource from the ActionEvent to Habanero // because marshalling loses the event's source. catch (ClassCastException evt) { outArea.append("Error: source isn't a TextField!\n"); return; } outArea.append(f.getText()+"\n"); f.selectAll(); } } // added all the methods below this line protected void writeHablet(MarshallOutputStream out) throws IOException { out.writeObject(outArea); } protected void readHablet(MarshallInputStream in) throws IOException { try { outArea=(TextArea)in.readObject(); } catch (ClassNotFoundException e) { Habanero.println("Object read was not a TextArea."); } } public void startInFrame(MirrorFrame f) { init(); start(); f.setTitle("Habanerized TextDemo"); f.add("Center", this); f.setSize(500,200); f.setVisible(true); f.show(); try { Habanero.addSharedEventType( Class.forName("java.awt.event.ActionEvent"), this); } catch (ClassNotFoundException e) { Habanero.println("could not find ActionEvent class object."); } } }