home | O'Reilly's CD bookshelfs | FreeBSD | Linux | Cisco | Cisco Exam  


Java AWT

Previous Chapter 19
java.awt Reference
Next
 

Choice

Name

Choice

[Graphic: Figure from the text]

Description

The Choice is a Component that provides a drop-down list of choices to choose from.

Class Definition

public class java.awt.Choice
    extends java.awt.Component
    implements java.awt.ItemSelectable {
  
  // Constructors
  public Choice();
  
  // Instance Methods
  public synchronized void add (String item); (New)
  public synchronized void addItem (String item); (Deprecated)
  public void addItemListener (ItemListener l); (New)
  public void addNotify();
  public int countItems();  (Deprecated)
  public String getItem (int index);
  public int getItemCount(); (New)
  public int getSelectedIndex();
  public synchronized String getSelectedItem();
  public synchronized Object[] getSelectedObjects(); (New)
  public synchronized void insert (String item, int index); (New)
  public synchronized void remove (int position); (New)
  public synchronized void remove (String item); (New)
  public synchronized void removeAll(); (New)
  public void removeItemListener (ItemListener l); (New)
  public synchronized void select (int pos);
  public synchronized void select (String str);
  
  // Protected Instance Methods
  protected String paramString();
  protected void processEvent (AWTEvent e);  (New)
  protected void processItemEvent (ItemEvent e); (New)
}

Constructors

Choice

public Choice()

Description

Constructs a Choice object.

Instance Methods

add

public synchronized void add (String item) (New)

Parameters

item

Text for new entry.

Throws

NullPointerException

If item is null.

Description

Adds a new entry to the available choices.

addItem

public synchronized void addItem (String item) (Deprecated)

Parameters

item

Text for new entry.

Throws

NullPointerException

If item is null.

Description

Replaced by add(String).

addItemListener

public void addItemListener (ItemListener l) (New)

Parameters

l

The listener to be added.

Implements

ItemSelectable.addItemListener(ItemListener l)

Description

Adds a listener for the ItemEvent objects this Choice generates.

addNotify

public void addNotify()

Overrides

Component.addNotify()

Description

Creates Choice's peer.

countItems

public int countItems() (Deprecated)

Returns

Number of items in the Choice.

Description

Replaced by getItemCount().

getItem

public String getItem (int index)

Parameters

index

Position of entry.

Returns

A string for an entry at a given position.

Throws

ArrayIndexOutOfBoundsException

If index is invalid; indices start at zero.

getItemCount

public int getItemCount() (New)

Returns

Number of items in the Choice.

getSelectedIndex

public int getSelectedIndex()

Returns

Position of currently selected entry.

getSelectedItem

public synchronized String getSelectedItem()

Returns

Currently selected entry as a String.

getSelectedObjects

public synchronized Object[] getSelectedObjects() (New)

Implements

ItemSelectable.getSelectedObjects()

Description

A single-item array containing the current selection.

insert

public synchronized void insert (String item, int index) (New)

Parameters

item

The string to add.

index

The position for the new string.

Throws

IllegalArgumentException

If index is less than zero.

Description

Inserts item in the given position.

remove

public synchronized void remove (int position) (New)

Parameters

position

The index of an entry in the Choice component.

Description

Removes the entry in the given position.

public synchronized void remove (String string) (New)

Parameters

string

Text of an entry within the Choice component.

Throws

IllegalArgumentException

If string is not in the Choice.

Description

Makes the first entry that matches string the selected item.

removeAll

public synchronized void removeAll() (New)

Description

Removes all the entries from the Choice.

removeItemListener

public void removeItemListener (ItemListener l) (New)

Parameters

l

The listener to be removed.

Implements

ItemSelectable.removeItemListener (ItemListener l)

Description

Removes the specified ItemListener so it will not receive ItemEvent objects from this Choice.

select

public synchronized void select (int pos)

Parameters

pos

The index of an entry in the Choice component.

Throws

IllegalArgumentException

If the position is not valid.

Description

Makes the entry in the given position.

public synchronized void select (String str)

Parameters

str

Text of an entry within the Choice component.

Description

Makes the first entry that matches str the selected item for the Choice.

Protected Instance Methods

paramString

protected String paramString()

Returns

A string with current settings of Choice.

Overrides

Component.paramString()

Description

Helper method for toString() to generate string of current settings.

processEvent

protected void processEvent (AWTEvent e) (New)

Parameters

e

The event to process.

Description

Low level AWTEvents are passed to this method for processing.

processItemEvent

protected void processItemEvent (ItemEvent e) (New)

Parameters

e

The item event to process.

Description

Item events are passed to this method for processing. Normally, this method is called by processEvent().

See Also

Component, ItemSelectable, String


Previous Home Next
CheckboxMenuItem Book Index Color

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