    All Packages  Class Hierarchy  This Package  Previous  Next  Index

# Class java.awt.Choice

    java.lang.Object
       |
       +----java.awt.Component
               |
               +----java.awt.Choice

public class Choice
extends Component
implements ItemSelectable

The Choice class is a pop-up menu of choices. The current choice is displayed as the title of the menu.

##

Choice()
  Constructs a new Choice.

##

add(String)
  Adds an item to this Choice.
addItem(String)
  Adds an item to this Choice.
addItemListener(ItemListener)
  Adds the specified item listener to recieve item events from this choice.
addNotify()
  Creates the Choice's peer.
countItems()
  Deprecated.
getItem(int)
  Returns the String at the specified index in the Choice.
getItemCount()
  Returns the number of items in this Choice.
getSelectedIndex()
  Returns the index of the currently selected item.
getSelectedItem()
  Returns a String representation of the current choice.
getSelectedObjects()
  Returns an array (length 1) containing the currently selected item.
insert(String, int)
  Inserts the item into this choice at the specified position.
paramString()
  Returns the parameter String of this Choice.
processEvent(AWTEvent)
  Processes events on this choice.
processItemEvent(ItemEvent)
  Processes item events occurring on this choice by dispatching them to any registered ItemListener objects.
remove(int)
  Removes an item from the choice menu.
remove(String)
  Remove the first occurrence of item from the choice menu.
removeAll()
  Removes all items from the choice menu.
removeItemListener(ItemListener)
  Removes the specified item listener so that it no longer receives item events from this choice.
select(int)
  Selects the item with the specified postion.
select(String)
  Selects the item with the specified String.

##

Choice

      public Choice()

  Constructs a new Choice.

##

addNotify

      public void addNotify()

  Creates the Choice's peer. This peer allows us to change the look of the Choice without changing its functionality.

  Overrides:
    addNotify in class Component

getItemCount

      public int getItemCount()

  Returns the number of items in this Choice.

  See Also:
    getItem

countItems

      public int countItems()

  Note: countItems() is deprecated. As of JDK version 1.1, replaced by getItemCount().

getItem

      public String getItem(int index)

  Returns the String at the specified index in the Choice.

  Parameters:
    index - the index at which to begin
  See Also:
    getItemCount

add

      public synchronized void add(String item)

  Adds an item to this Choice.

  Parameters:
    item - the item to be added
  Throws: NullPointerException
    If the item's value is equal to null.

addItem

      public synchronized void addItem(String item)

  Adds an item to this Choice.

  Parameters:
    item - the item to be added
  Throws: NullPointerException
    If the item's value is equal to null.

insert

      public synchronized void insert(String item,
                                      int index)

  Inserts the item into this choice at the specified position.

  Parameters:
    item - the item to be inserted
    index - the position at which the item should be inserted
  Throws: IllegalArgumentException
    if index is less than 0.

remove

      public synchronized void remove(String item)

  Remove the first occurrence of item from the choice menu.

  Parameters:
    item - the item to remove from the choice menu
  Throws: IllegalArgumentException
    If the item doesn't exist in the choice menu.

remove

      public synchronized void remove(int position)

  Removes an item from the choice menu.

removeAll

      public synchronized void removeAll()

  Removes all items from the choice menu.

  See Also:
    remove, delItems

getSelectedItem

      public synchronized String getSelectedItem()

  Returns a String representation of the current choice.

  See Also:
    getSelectedIndex

getSelectedObjects

      public synchronized Object[] getSelectedObjects()

  Returns an array (length 1) containing the currently selected item. If this choice has no items, returns null.

  See Also:

getSelectedIndex

      public int getSelectedIndex()

  Returns the index of the currently selected item.

  See Also:
    getSelectedItem

select

      public synchronized void select(int pos)

  Selects the item with the specified postion.

  Parameters:
    pos - the choice item position
  Throws: IllegalArgumentException
    If the choice item position is invalid.
  See Also:
    getSelectedItem, getSelectedIndex

select

      public synchronized void select(String str)

  Selects the item with the specified String.

  Parameters:
    str - the specified String
  See Also:
    getSelectedItem, getSelectedIndex

addItemListener

      public void addItemListener(ItemListener l)

  Adds the specified item listener to recieve item events from this choice.

  Parameters:
    l - the item listener

removeItemListener

      public void removeItemListener(ItemListener l)

  Removes the specified item listener so that it no longer receives item events from this choice.

  Parameters:
    l - the item listener

processEvent

      protected void processEvent(AWTEvent e)

  Processes events on this choice. If the event is an ItemEvent, it invokes the handleItemEvent method, else it calls its superclass's processEvent.

  Parameters:
    e - the event
  Overrides:
    processEvent in class Component

processItemEvent

      protected void processItemEvent(ItemEvent e)

  Processes item events occurring on this choice by dispatching them to any registered ItemListener objects. NOTE: This method will not be called unless item events are enabled for this component; this happens when one of the following occurs: a) An ItemListener object is registered via addItemListener() b) Item events are enabled via enableEvents()

  Parameters:
    e - the item event
  See Also:
    enableEvents

paramString

      protected String paramString()

  Returns the parameter String of this Choice.

  Overrides:
    paramString in class Component

    All Packages  Class Hierarchy  This Package  Previous  Next  Index