Skip to Content

Determine If The Index Is Selected AWT List Example

  • strict warning: Non-static method view::load() should not be called statically in /home/javaexa1/public_html/sites/all/modules/views-6.x-2.16/views/views.module on line 906.
  • strict warning: Declaration of views_handler_argument::init() should be compatible with views_handler::init(&$view, $options) in /home/javaexa1/public_html/sites/all/modules/views-6.x-2.16/views/handlers/views_handler_argument.inc on line 0.
  • strict warning: Declaration of views_handler_filter::options_validate() should be compatible with views_handler::options_validate($form, &$form_state) in /home/javaexa1/public_html/sites/all/modules/views-6.x-2.16/views/handlers/views_handler_filter.inc on line 0.
  • strict warning: Declaration of views_handler_filter::options_submit() should be compatible with views_handler::options_submit($form, &$form_state) in /home/javaexa1/public_html/sites/all/modules/views-6.x-2.16/views/handlers/views_handler_filter.inc on line 0.
  • strict warning: Declaration of views_handler_filter_boolean_operator::value_validate() should be compatible with views_handler_filter::value_validate($form, &$form_state) in /home/javaexa1/public_html/sites/all/modules/views-6.x-2.16/views/handlers/views_handler_filter_boolean_operator.inc on line 0.
  • strict warning: Declaration of views_plugin_style_default::options() should be compatible with views_object::options() in /home/javaexa1/public_html/sites/all/modules/views-6.x-2.16/views/plugins/views_plugin_style_default.inc on line 0.
  • strict warning: Declaration of views_plugin_row::options_validate() should be compatible with views_plugin::options_validate(&$form, &$form_state) in /home/javaexa1/public_html/sites/all/modules/views-6.x-2.16/views/plugins/views_plugin_row.inc on line 0.
  • strict warning: Declaration of views_plugin_row::options_submit() should be compatible with views_plugin::options_submit(&$form, &$form_state) in /home/javaexa1/public_html/sites/all/modules/views-6.x-2.16/views/plugins/views_plugin_row.inc on line 0.

  1. /*
  2.         Determine If The Index Is Selected AWT List Example
  3.         This java example shows how to determine if the specific index is selected
  4.         from a list using Java AWT List class.
  5. */
  6.  
  7. import java.applet.Applet;
  8. import java.awt.Graphics;
  9. import java.awt.List;
  10. import java.awt.event.ItemEvent;
  11. import java.awt.event.ItemListener;
  12.  
  13. /*
  14. <applet code="DetermineIfIndexIsSelected" width=200 height=200>
  15. </applet>
  16. */
  17.  
  18. public class DetermineIfIndexIsSelected extends Applet implements ItemListener{
  19.        
  20.         List list = null;
  21.        
  22.         public void init(){
  23.                
  24.                 //create a list
  25.                 list = new List(5, true);
  26.                
  27.                 //add items to a list  
  28.                 list.add("One");
  29.                 list.add("Two");
  30.                 list.add("Three");
  31.                 list.add("Four");
  32.                 list.add("Five");
  33.                 list.add("Six");
  34.                 list.add("Seven");
  35.                
  36.                 //add list
  37.                 add(list);
  38.                
  39.                 //add listener
  40.                 list.addItemListener(this);
  41.        
  42.         }
  43.  
  44.         public void paint(Graphics g){
  45.                
  46.                 /*
  47.                  * To determine if the specific index of AWT list is selected or not, use
  48.                  * boolean isIndexSelected(int index)
  49.                  * method.
  50.                  */
  51.                
  52.                 g.drawString("Is index 2 selected? : " + list.isIndexSelected(2), 10, 120);
  53.         }
  54.        
  55.         public void itemStateChanged(ItemEvent ie) {
  56.                 repaint();             
  57.         }
  58.  
  59.        
  60. }

Example Output