Javase Project event class (ItemEvent)

Source: Internet
Author: User

{Related Information}
The Project event class (ItemEvent) refers to a semantic event that an item is selected and canceled. Selecting a CheckBox, ComboBox, List , Choice , and other components will result in a project event. Using Project events, you must add an event handler that implements the ItemListener interface to the component, which has the following methods:
void Itemstatechange (ItemEvent e)

{Specific Instance description}
function description, each item selected will display relevant information in the text area, as follows:

{Specific Instance code}

 PackageSup.orange.learn;Importjava.awt.*;Importjava.awt.event.ItemEvent;ImportJava.awt.event.ItemListener;ImportJava.awt.event.WindowAdapter;Importjava.awt.event.WindowEvent;/*** Created by Re-x on 10/30/14.*/ Public classItemeventdemoextendsFrameImplementsitemlistener{list List;    Checkbox CheckBox1, CheckBox2, Checkbox3;    Choice Colorchooser;    TextArea TextArea;  PublicItemeventdemo () {Super();    Init (); }     Public Static voidMain (string[] args) {NewItemeventdemo (); }     Public voidinit () {setlayout (NewGridLayout (4, 1)); TextArea=NewTextArea ();        Add (textarea); List=NewList (4,false); List.add ("Chinese"); List.add ("Math"); List.add ("中文版"); List.add ("Physics"); List.add ("Chemistry"); List.add ("History"); List.add ("Geography");        Add (list); List.additemlistener ( This); Panel Panel=NewPanel (); CheckboxGroup CBG=NewCheckboxGroup (); CheckBox1=NewCheckBox ("One", CBG,true); Checkbox1.additemlistener ( This);        Panel.add (CheckBox1); CheckBox2=NewCheckBox ("Both", CBG,false); Checkbox2.additemlistener ( This);        Panel.add (CHECKBOX2); Checkbox3=NewCheckBox ("Three", CBG,true); Checkbox3.additemlistener ( This);        Panel.add (CHECKBOX3);        Add (panel); Colorchooser=NewChoice (); Colorchooser.add ("Red"); Colorchooser.add ("Green"); Colorchooser.add ("Black"); Colorchooser.additemlistener ( This);        Add (Colorchooser); Addwindowlistener (NewWindowadapter () {@Override Public voidwindowclosing (windowevent e) {Super. windowclosing (e);                Dispose (); System.exit (0);        }        }); SetSize (300, 500); SetVisible (true); }     Public voiditemstatechanged (itemevent e) {if(E.getsource () = =list)        {Textarea.settext (List.getselecteditem ()); }        Else if(E.getsource () = =CheckBox1)        {Textarea.settext (Checkbox1.getlabel ()); }        Else if(E.getsource () = =checkbox2)        {Textarea.settext (Checkbox2.getlabel ()); }        Else if(E.getsource () = =checkbox3)        {Textarea.settext (Checkbox3.getlabel ()); }        Else if(E.getsource () = =Colorchooser)        {Textarea.settext (Colorchooser.getselecteditem ()); }    }}

Javase Project event class (ItemEvent)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.