Java Technology Home Page
A-Z Index

Java Developer Connection(SM)
Online Training

Downloads, APIs, Documentation
Java Developer Connection
Tutorials, Tech Articles, Training
Online Support
Community Discussion
News & Events from Everywhere
Products from Everywhere
How Java Technology is Used Worldwide
Print Button
 

Help is available for each task.



    Task 1

    To receive the item events, add the applet itself as an ItemListener target. That is, the applet should implement this interface.


    To the class definition, add:

    implements ItemListener
    

    In the init() method, add:

    list.addItemListener(this);
    

    This means that the current applet is functioning as the listener, that is, the target, for all item events distributed by the source, in this case, list. Thus, this object, that is, the applet, must define the method(s) specified in the ItemListener interface.

    Task 2

    Define the itemStateChanged() method so that it calls getSelectedItem() to get the currently selected item and displays it in the textfield, tf, with setText().


      public void itemStateChanged(ItemEvent e) {
        String item =
         list.getSelectedItem(); if
        (item ! = 
          null && item.length() >  0)
          tf.setText(item);
        else
          tf.setText("No font selection.");
      }
    

Copyright 1996-2000 jGuru.com. All Rights Reserved.


Print Button
[ This page was updated: 14-Jul-2000 ]
Products & APIs | Developer Connection | Docs & Training | Online Support
Community Discussion | Industry News | Solutions Marketplace | Case Studies
Glossary - Applets - Tutorial - Employment - Business & Licensing - Java Store - Java in the Real World
FAQ | Feedback | Map | A-Z Index
For more information on Java technology
and other software from Sun Microsystems, call:
(800) 786-7638
Outside the U.S. and Canada, dial your country's AT&T Direct Access Number first.
Sun Microsystems, Inc.
Copyright © 1995-2000 Sun Microsystems, Inc.
All Rights Reserved. Terms of Use. Privacy Policy.