Page 2 :
1.3 AWT Controls and Layout Managers:, , , Choice Controls:, , , , The Choice class is used to create a pop-up list of items, from which the user may choose. Thus, a Choice control, is a form of menu., , , , When inactive, a Choice component takes up only, enough space to show the currently selected item., , DJ Sir
Page 3 :
1.3 AWT Controls and Layout Managers:, , , Choice Controls:, , , , When the user clicks on it, the whole list of choices pops, up, and a new selection can be made., , , , Each item in the list is a string that appears as a leftjustified label in the order it is added to the Choice, object., , DJ Sir
Page 4 :
1.3 AWT Controls and Layout Managers:, , , Choice Controls: Constructor, , , , Choice only defines the default constructor, which, creates an empty list., , , , Constructor:, Choice(), , DJ Sir
Page 5 :
1.3 AWT Controls and Layout Managers:, , , Choice Controls: Method, , , , In order to add a selection to the list, add( ) is used., void add(String name), , , , Here, name is the name of the item being added., , , , Items are added to the list in the order in which calls to, add( ) occur., , DJ Sir
Page 6 :
1.3 AWT Controls and Layout Managers:, , , Choice Controls: Method, , , , In order to determine which item is currently selected,, we may call either any of the following methods:, String getSelectedItem( ), int getSelectedIndex( ), , , , The getSelectedItem( ) method returns a string, containing the name of the item., , DJ Sir
Page 7 :
1.3 AWT Controls and Layout Managers:, , , Choice Controls: Method, , , , getSelectedIndex( ) returns the index of the item., , , , The first item is at index 0. By default, the first item, added to the list is selected., , , , For obtaining the number of items in the list, call, getItemCount( )., int getItemCount( ), , DJ Sir
Page 8 :
1.3 AWT Controls and Layout Managers:, , , Choice Controls: Method, , , , We can set the currently selected item using the select( ), method with either a zero-based integer index or a string, that will match a name in the list., void select(int index), void select(String name), , DJ Sir
Page 9 :
1.3 AWT Controls and Layout Managers:, , , Choice Controls: Method, , , , Given an index, we can obtain the name associated with, the item at that index by calling getItem( )., String getItem(int index), , , , Here, index specifies the index of the desired item., , DJ Sir
Page 10 :
1.3 AWT Controls and Layout Managers:, , , Handling Choice Controls:, , , , Each time a choice is selected, an item event is, generated., , , , This is sent to any listeners that previously registered an, interest in receiving item event notifications from that, component., , DJ Sir
Page 11 :
1.3 AWT Controls and Layout Managers:, , , Handling Choice Controls:, , , , Each listener implements the ItemListener interface. That, interface defines the itemStateChanged( ) method., , , , An ItemEvent object is supplied as the argument to this, method., , DJ Sir
Page 12 :
1.3 AWT Controls and Layout Managers:, , , Choice Controls: Example, , DJ Sir