
[ Previous ] [ Index ] [ Next ]


|
|
This pattern assumes that your applet uses the Java 1.1 event model. If your applet uses the Java 1.0 event model, please read Using the Old Event Model. [Not yet written] |
ID so that you can specify a particular event within an event type. For
example, if your event type is java.awt.event.MouseEvent,
and the id is MOUSE_DOWN, then only mouse down events
will be shared because of this statement. If you leave out the id,
as in the first line, then all mouse events would be shared.
The Mirrorable m supplies Habanero the current hablet, so you just pass the pseudovariable this to it, as illustrated in the running example below. (This is an example of double dispatching.)
These sharing calls should go in the startInFrame() method
of your hablet that we explained
in Change Superclass, Imports, Initialization.
| Running Example from the example of habanerizing TextDemo.java. |
| Add or modify this method in the class HabTextDemo:
public void startInFrame(MirrorFrame f)
// Code for setting the default window parameters goes here. try
|
|
|
Note how we use a try...catch construct in case we get an exception. |
| Running Example from the example of habanerizing TextDemo.java. |
Because TextDemo.java does call getSource(), change the body
of HabTextDemo.FieldListener.actionPerformed() to:
try {f = (TextField)Habanero.getSource();}
// change getSource from the ActionEvent to Habanero
// because serializing loses the event's source.
catch (ClassCastException evt)
{ outArea.append("Error: source isn't a TextField!\n");
return;
}
outArea.append(e.getActionCommand()+"\n");
// change because if we did the original f.getText() we
// would get the text from the *local* copy of the field
// and not the one in the original Hablet.
f.selectAll();
|
See the Event Model, part B for a diagram of how this event sharing works.
Habanero® is a registered trademark owned by The Board of Trustees of the University of Illinois. Copyright 1996-1998. All rights reserved. Java(TM) is a proprietary trademark owned by Sun Microsystems, Inc.
![]()
The National Center for Supercomputing Applications
University of Illinois at Urbana-Champaign
Contacts page