Class ListWindow

java.lang.Object
  |
  +--ListWindow

public class ListWindow
extends java.lang.Object

A ListWindow is a window which presents a list of strings and lets the user select one of them. The ListWindow can for example be used for presenting a list of chat participants and selecting one participant might be used to indicate that a private chat should be initiated. Input, that is selecting a string in the list, is handled by the elementSelected method which is called automatically whenever the user selects an item in the list. The intention is that the ListWindow class should be used as a super class to another class which overloads the elementSelected method. The overloaded method should contain the Java code to be executed, if any, when an element is selected. It is also possible to ask the ListWindow at any time which element is currently selected. Another possible way of using the class is to modify the ListWindow class directly, putting the code to be executed when a new message is entered directly in the elementSelected method.


Constructor Summary
ListWindow(int x, int y, java.lang.String title)
          Constructs a ListWindow at a given position on the screen and with a given title which is displayed in the title bar of the window.
 
Method Summary
 void add(java.lang.String element)
          Adds a new element to the end of the list presented in the ListWindow.
 void clear()
          Clears the contents of the ListWindow and removes all elements in the list.
 void destroy()
          Destroys the ListWindow and frees all resources associated with it.
 void elementSelected(java.lang.String element, int position)
          Returns the text associated with the currently selected item.
 int getSelectedPosition()
          Returns the index of the currently selected item, if any, in the list.
 void hide()
          Makes the ListWindow invisible.
 void show()
          Makes the ListWindow visible.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ListWindow

public ListWindow(int x,
                  int y,
                  java.lang.String title)
Constructs a ListWindow at a given position on the screen and with a given title which is displayed in the title bar of the window. Note that the window is initially invisible. You must call the show method in order to display the window.

Note: Depending on which window manager/window system you use, both window title and position might be ignored.

Parameters:
x - the x coordinate of the position of the window
y - the y coordinate of the position of the window
title - a String containing the title to be displayed in the title bar of the window
Method Detail

add

public void add(java.lang.String element)
Adds a new element to the end of the list presented in the ListWindow.

Parameters:
element - a string containing the text which is to be displayed in the ListWindow

clear

public void clear()
Clears the contents of the ListWindow and removes all elements in the list.


hide

public void hide()
Makes the ListWindow invisible. Call show to make the window visible again.

See Also:
show()

show

public void show()
Makes the ListWindow visible. ListWindows is initially invisible when having been created. To actually make it visible you must call the show method. Call hide to make the window invisible again.

See Also:
hide()

destroy

public void destroy()
Destroys the ListWindow and frees all resources associated with it. The destroy method should be called when the ListWindow is not needed anymore. Note that it is ILLEGAL to call any method of the ListWindow object once destroy has been called.


getSelectedPosition

public int getSelectedPosition()
Returns the index of the currently selected item, if any, in the list. The first item is numbered 0.

Returns:
the index of the selected item. If no item is selected the method returns -1.

elementSelected

public void elementSelected(java.lang.String element,
                            int position)
Returns the text associated with the currently selected item.

Parameters:
element - a String containing the text of the selected element
position - the index of the selected element
Returns:
a string containing the text of the selected element. If no item is selected, null is returned. public String getSelected() { String result; if (!destroyed) { result = theList.getSelectedItem(); } else { result = null; } return result; } /** The elementSelected method is called whenever the user selects an element in the ListWindow. The intention is that this method should be overloaded in a subclass to ListWindow. The default implementation found in the ListWindow class does nothing.