Core Java| JSP| Servlets| XML| EJB| JEE5| Web Services| J2ME| Glossary| Questions?

 

 

 

 

 

 

 

 

 

 

 

 

 

Search Tutorials

Latest Questions
Comments
 
Item Events in Java 
 

In this section, you will learn about handling item events in java.

 

Item Events in Java

                         

Introduction

In this section, you will learn about handling item events in java. This demonstrates that the event generated when you select an item from the group of the items.

This program demonstrates how the item events is handled. You can perform several operations according to the selecting of  items from the item group.

Here, you will see the handling item event through the given program in which, a combo box and a text area have been taken. Items of the combo box are as follows : Red, Green, Blue. If you select an item from the combo box then the message with the item name will be displayed in the text area.

Choice() :
This is the constructor of the Choice class which creates combo box.

ItemEvent :
This is the ItemEvent class which indicates  an event on selecting or deselecting items from the item group. This event is passed by ItemListener object. The generated event is passed to all ItemListener objects which is registered to receive such types of event. This is done using the addItemListener() method of the object.

getItem() :
This is the method of the ItemEvent class which returns the value of the selected or deselected item.

Here is  the code of program :

import java.awt.*;
import java.awt.event.*;

public class AwtItemEvent extends Frame{
  TextArea txtArea;
  public AwtItemEvent(String title){
    super(title);
    txtArea = new TextArea();
    add(txtArea, BorderLayout.CENTER);
    Choice choice = new Choice();
    choice.addItem("red");
    choice.addItem("green");
    choice.addItem("blue");
    choice.addItemListener(new ItemListener(){
      public void itemStateChanged(ItemEvent e){
        txtArea.setText("This is the " + e.getItem() " color.\n");
      }
    });
    addWindowListener(new WindowAdapter(){
      public void windowClosing(WindowEvent e){
        System.exit(0);
      }
    });
    add(choice, BorderLayout.NORTH);
    setSize(400,400);
    setVisible(true);
    setResizable(false);
  }
  
  public static void main(String[] args){
    AwtItemEvent f = new AwtItemEvent("AWT Demo");
  }
}

Download this example.

                         

» View all related tutorials
Related Tags: c class make method sed boolean value ole set oo frame if boo to ram bool argument e il not

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

Audio Version
Reload Image
 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 

Current Comments

1 comments so far (
post your own) View All Comments Latest 10 Comments:

wannt a program which creates a frame n closes the frame by one click on the button in the frame named exit

Posted by priyanka on Monday, 05.14.07 @ 15:55pm | #15848

Training Courses
Tell A Friend
Your Friend Name
Software Solutions
Least Viewed
Most Rated
Recently Viewed
Search Tutorials

 

 
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Indian Software Development Company | iPhone Development Company in India | Flex Development Company in India | Java Training Delhi | Java Training at Noida |

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2008. All rights reserved.