Home | Ajax | BioInformatics | Dojo | EAI | EJB | Hibernate | J2ME | Java | Java Glossary | Java Servlets | JavaScript | Jboss | JDBC | JDO | Jmeter | JSF | JSP | JUnit | Maven | MySQL | Spring Framework | SQL | Struts | Technology | WAP | Web Services | XML


 
  
 
Programming Tutorials: Ajax | Articles | JSP | Bioinformatics | Database | Free Books | Hibernate | J2EE | J2ME | Java | JavaScript | JDBC | JMS | Linux | MS Technology | PHP | RMI | Web-Services | Servlets | Struts | UML
 

 
Facing Programming Problem?
Ask Questions?, Browse Latest Questions, Question-Answer Guidelines
Java
  JDO Tutorials
  EAI Articles
  Struts Tutorials
  Java Tutorials
  Java Certification
  Java Applet
Questions
Comments

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.

                         

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

Latest Searches:
how to draw a transpar
NamedQuery
java thread
javascript to display
struts2
Hash Function in Java
java beans
sฦ�ing
Photoshop Drawing Rain
login window
struttutorial
iterator
sybase create command
creating tabs
inset the value into t
decimal
update jsf
Combattons la programm
breakÑ?â??â??Ñ??Ñ?â???
Jasper Reports
How to restore page vi
validate radio button
form capture
gridback
jbossweb installation
shapes in applet
Visual Basic Animation
word count in a file
populate drop down
html:frame
string programe in jav
how to get applicate s
jpf
beans
PHP Date and .....:/pw
SimplyMEPIS 3.4-3 is r
varStatus
value change listener
program to invoke ejb
java arrays
JDBC
struts listbox
ActionScript
multidimensional Array
insert data to text fi
Read Cookies from Serv
Photoshop
ActionSupport.java
PHP Date and .....:/pw
how to find the days b
white spaces are requi
JavaScript functions
break?�¢�????????�
breakå??ç?­?å?????å??ç
java structures
how to create two drop
self-avoiding random w
Get first day of week
filechannel
struts 2 iterator
Multi-tier application
file search in directo
class path
input in array
Photoshop Text Effect
how to use indexof in
Struts HTML EL tags
Java General Java Enca
Configure
how to increase the er
<hx:fileProp
<logic:iterator>
pseudocode of magic sq
ล ยà¸?ฤ??????à¸
FileInputStream
struts2 csv result
Dreamweaver Behaviors
Mysql and jsp
custom tags
how to increase the er
Java String toLowerCase Example
Java String toCharArray Example
Java String substring Example
Java String indexOf Example
Java String startsWith Example
Java String hashCode Example
Java String matches Example
Java String length Example
Java String lastIndexOf Example
Java String isEmpty Example
Java String equalsIgnoreCase Example
Java String equals Example
Java String endsWith Example
Java String copyValueOf Example
Java String contentEquals Example
  EAI Articles
  Java Certification
Tell A Friend
Your Friend Name
Search Tutorials

 

 
 
Browse all Java Tutorials
Java JSP Struts Servlets Hibernate XML
Ajax JDBC EJB MySQL JavaScript JSF
Maven2 Tutorial JEE5 Tutorial Java Threading Tutorial Photoshop Tutorials Linux Technology
Technology Revolutions Eclipse Spring Tutorial Bioinformatics Tutorials Tools SQL
 

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 | 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.