package com.mindprod.example;
import java.awt.Color;
import java.awt.Font;
import java.awt.Frame;
import java.awt.List;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import static java.lang.System.*;
/**
* example use of java.awt.List not to be confused with java.util.List.
*
* @author Roedy Green, Canadian Mind Products
* @version 1.0 2009-01-01 initial version
* @since 2009-01-01
*/
public final class TestList
{
private static final Color FOREGROUND_FOR_LABEL = new Color( 0x0000b0 );
/**
* Debugging harness for a Frame
*
* @param args command line arguments are ignored.
*/
public static void main( String args[] )
{
final Frame frame = new Frame();
final List flavour = new List();
flavour.setForeground( FOREGROUND_FOR_LABEL );
flavour.setBackground( Color.WHITE );
flavour.setFont( new Font( "Dialog", 15, Font.PLAIN ) );
flavour.add( "strawberry" );
flavour.add( "chocolate" );
flavour.add( "vanilla" );
flavour.select( 0 );
flavour.setMultipleMode( true );
flavour.addItemListener( new ItemListener()
{
/**
* Invoked when an item has been selected or deselected by the user.
* The code written for this method performs the operations that
* need to occur when an item is selected (or deselected).
*/
public void itemStateChanged( ItemEvent e )
{
out.println( "--selection--" );
String choice = flavour.getSelectedItem();
out.println( choice );
int which = flavour.getSelectedIndex();
out.println( which );
out.println( "--multiples--" );
String[] choices = flavour.getSelectedItems();
for ( String aChoice : choices )
{
out.println( aChoice );
}
int[] indexes = flavour.getSelectedIndexes();
for ( int index : indexes )
{
out.println( index );
}
}
} );
frame.add( flavour );
frame.setSize( 100, 100 );
frame.addWindowListener( new WindowAdapter()
{
/**
* Handle request to shutdown.
* @param e event giving details of closing.
*/
public void windowClosing( WindowEvent e )
{
System.exit( 0 );
}
}
);// end addWindowListener line
frame.validate();
frame.setVisible( true );
}
}