javabook
Class ListBox

java.lang.Object
  extended byjavabook.JavaBookDialog
      extended byjavabook.ListBox

public class ListBox
extends JavaBookDialog

This dialog is for listing a list of items from which the user can select. You can get the index or the string value of the item the user selects. If the user closes the dialog without clicking any button or clicks the Cancel button, then the result is CANCEL (getSelectedIndex) or NO_ITEM (getSelectedItem). If the user clicks the OK button without selecting an item, then the result is CANCEL or NO_ITEM. If the user selects an item and clicks the OK button, then the index or the string value of the selected item is returned.

This class is provided as freeware. You are free to use as provided or modify to your heart's content. But you use it at your own risk. No implied or explicit warranty is given.


Field Summary
static int CANCEL
          Constant to represent a user action where the Cancel button is clicked or the dialog is closed.
static java.lang.String NO_ITEM
          Constant to represent no selection for the getSelectedItem method.
static int NO_SELECTION
          Constant to represent a user action where the Ok button is clicked, but no item is selected from the list.
 
Fields inherited from class javabook.JavaBookDialog
ERROR_ICON, INFO_ICON, NO_ICON, QUESTION_ICON, WARNING_ICON
 
Constructor Summary
ListBox(java.awt.Frame owner)
          Constructs the standard modal ListBox dialog with 'owner' as its owner.
ListBox(java.awt.Frame owner, boolean modal)
          Constructs a ListBox dialog with 'owner' as its owner and default title.
ListBox(java.awt.Frame owner, java.lang.String title)
          Constructs a modal ListBox dialog with 'owner' as its owner and 'title' as its title.
ListBox(java.awt.Frame owner, java.lang.String title, boolean modal)
          Constructs a ListBox dialog with 'owner' as its owner and 'title' as its title.
 
Method Summary
 void addItem(java.lang.String item)
          Adds an item to the list.
 void deleteItem(int index)
          Deletes an item at position index from the list.
 void deleteItem(java.lang.String item)
          Deletes an item from the list.
 java.lang.String getItemFromIndex(int index)
          Returns the string value of an iten given index.
 int getSelectedIndex()
          Prompts the user to select an item.
 java.lang.String getSelectedItem()
          Prompts the user to select an item.
 
Methods inherited from class javabook.JavaBookDialog
setIcon, setLocation, setTitle
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NO_SELECTION

public static final int NO_SELECTION
Constant to represent a user action where the Ok button is clicked, but no item is selected from the list.

See Also:
Constant Field Values

CANCEL

public static final int CANCEL
Constant to represent a user action where the Cancel button is clicked or the dialog is closed.

See Also:
Constant Field Values

NO_ITEM

public static final java.lang.String NO_ITEM
Constant to represent no selection for the getSelectedItem method.

Constructor Detail

ListBox

public ListBox(java.awt.Frame owner)
Constructs the standard modal ListBox dialog with 'owner' as its owner.

Parameters:
owner - a Frame object owner of this dialog

ListBox

public ListBox(java.awt.Frame owner,
               java.lang.String title)
Constructs a modal ListBox dialog with 'owner' as its owner and 'title' as its title.

Parameters:
owner - a Frame object owner of this dialog
title - the title of this title

ListBox

public ListBox(java.awt.Frame owner,
               boolean modal)
Constructs a ListBox dialog with 'owner' as its owner and default title. This dialog is modal if 'modal' is true; otherwise, it is modeless.

Parameters:
owner - a Frame object owner of this dialog
modal - true for modal; false for modeless

ListBox

public ListBox(java.awt.Frame owner,
               java.lang.String title,
               boolean modal)
Constructs a ListBox dialog with 'owner' as its owner and 'title' as its title. This dialog is modal if 'modal' is true; otherwise, it is modeless.

Parameters:
owner - a Frame object owner of this dialog
title - the title of this title
modal - true for modal; false for modeless
Method Detail

addItem

public void addItem(java.lang.String item)
Adds an item to the list.

Parameters:
item - a String value to add to the list

deleteItem

public void deleteItem(int index)
Deletes an item at position index from the list.

Parameters:
index - the position of an item to remove

deleteItem

public void deleteItem(java.lang.String item)
Deletes an item from the list.

Parameters:
item - the item to remove

getSelectedIndex

public int getSelectedIndex()
Prompts the user to select an item. If the user closes the dialog without clicking any button or clicks the Cancel button, then the result is CANCEL. If the user clicks the OK button without selecting an item, then the result is CANCEL. If the user selects an item and clicks the OK button, then the index of the selected item is returned.

Returns:
the index of the selected item in the list or the value CANCEL

getItemFromIndex

public java.lang.String getItemFromIndex(int index)
Returns the string value of an iten given index. If an invalid index is provided, then the value returned is NO_ITEM.

Parameters:
index - the index of an item to return
Returns:
the string value of an item at the index position. NO_ITEM is returned for an invalid index.

getSelectedItem

public java.lang.String getSelectedItem()
Prompts the user to select an item. If the user closes the dialog without clicking any button or clicks the Cancel button, then the result is NO_ITEM. If the user clicks the OK button without selecting an item, then the result is NO_ITEM. If the user selects an item and clicks the OK button, then the string value of the selected item is returned.

Returns:
the string value of the selected item in the list or the value NO_ITEM