Java AWT

Previous Chapter 9
Pick Me
Next
 

9.5 ItemSelectable

In Java 1.1, the classes Checkbox, Choice, List, and CheckboxMenuItem (covered in the next chapter) share a common interface that defines a method for getting the currently selected item or items. This means that you can use the same methods to retrieve the selection from any of these classes. More important, it means that you can write code that doesn't know what kind of selectable item it's working with. For example, you could write a method that returns the selectable component from some user interface. This method might have the signature:

public ItemSelectable getChooser();

After you call this method, you can read selections from the user interface without knowing exactly what you're dealing with.

Methods

public Object[] getSelectedObjects () (New)

The getSelectedObjects() method returns the currently selected item or items as an Object array. The return value is null if there is nothing selected.


Previous Home Next
CheckboxGroup Book Index Would You Like to Choose from the Menu?

Java in a Nutshell Java Language Reference Java AWT Java Fundamental Classes Exploring Java