Apple WebObjects 3.5 Instrukcja Użytkownika Strona 147

  • Pobierz
  • Dodaj do moich podręczników
  • Drukuj
  • Strona
    / 218
  • Spis treści
  • BOOKMARKI
  • Oceniono. / 5. Na podstawie oceny klientów
Przeglądanie stron 146
When You Don’t Have an Applet’s Source Code
147
1. Declare a subclass of the Association class.
class MyAssociation extends Association {
...
}
2. Implement the keys method to return a list (Vector) of keys managed by
the applet. See “When You Have an Applet’s Source Code” (page 144)
for an example.
3. Implement the
takeValueForKey and valueForKey methods to set and get the
values of keys. Use Association’s
destination method to obtain the
destination object (that is, the applet).
synchronized public Object valueForKey(String key) {
Object dest = this.destination();
if (key.equals("title")) {
return ((MyApplet)dest).getLabel();
}
}
synchronized public void takeValueForKey(Object value, String key) {
Object dest = this.destination();
if (key.equals("title")) {
if ((value != null) && !(value instanceof String)) {
System.out.println("Object value of wrong type set for key
'title'. Value must be a String.");
} else {
((MyApplet)dest).setLabel(((value == null)
? ""
: (String)value));
}
}
Note that the class of the destination applet (in this example,
MyApplet) must be cast.
If the applet triggers an action method, it must have some mechanism
for communicating this event to observers (such as an
observeGadget
method).
4. The Association responds to the triggering of the applet’s action by
sending
invokeAction to itself.
// fictictious method
public void observeGadget(Object sender, String action) {
if ((sender instanceof Gadget) && action.equals("vacuum")) {
this.invokeAction(action);
}
}
Note that in this hypothetical example, the Association must first set itself
up as an observer.
Przeglądanie stron 146
1 2 ... 142 143 144 145 146 147 148 149 150 151 152 ... 217 218

Komentarze do niniejszej Instrukcji

Brak uwag