Developing Java Beans synchronized (mappingTable) { tempmapping =

Developing Java Beans synchronized (mappingTable) { tempmapping = (Hashtable)mappingTable.clone(); } cnt = tempmapping.size(); stream.writeInt(cnt); // get the enumerations of the keys and values Enumeration keys = tempmapping.keys(); Enumeration vals = tempmapping.elements(); // store the keys and values for (int i = 0; i < cnt; i++) { // get the button and associated method Button b = (Button)keys.nextElement(); Method m = (Method)vals.nextElement(); // get the method name String name = m.getName(); // store the button and method name stream.writeObject(b); stream.writeObject(name); } } // handle the reading of the object state private void readObject(ObjectInputStream stream) throws IOException { // use default serialization for the non-transient members try { stream.defaultReadObject(); // get the number of mappings int cnt = stream.readInt(); // read the keys and values for the mapping for (int i = 0; i < cnt; i++) { // read the button and method name Button b = (Button)stream.readObject(); String name = (String)stream.readObject(); // add the mapping addMapping(b, name); } } catch (Exception e) { throw new IOException(); } } } Now let’s consider the ListeningPanel class. It contains three instances of java.awt.Button, and one instance of GenericButtonAdapter. The initialize() method creates the buttons and adds them to the panel. It also creates an instance of the adapter and then calls registerActionEventHandler() to register the event handlers associated with each button. page 86

Comments are closed.