|
Training Index
by
Exercise
API Docs
About This Short Course
Short Course
Exercises
Help is available for each task.
To receive the item events, add the applet itself as an ItemListener target. That is, the applet should implement this interface.
To the class definition, add:
implements ItemListener
In the init() method, add:
list.addItemListener(this);
This means that the current applet is functioning as the listener, that is, the target, for all item events distributed by the source, in this case, list.
Thus, this object, that is, the applet, must define the method(s) specified in the ItemListener interface.
Define the itemStateChanged() method so that it calls getSelectedItem() to get the currently selected item and displays it in the textfield, tf, with setText().
public void itemStateChanged(ItemEvent e) {
String item =
list.getSelectedItem(); if
(item ! =
null && item.length() > 0)
tf.setText(item);
else
tf.setText("No font selection.");
}
|
Copyright 1996-2000 jGuru.com. All Rights Reserved.
|