📄 190.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML><!-- This file edited for Java Jumpstart CD --> <HEAD><META VALUE="keyword" CONTENTS="codesamples"> <TITLE> Code Samples from the Java Developers Almanac 2000 </TITLE> <META NAME="AUTHOR" CONTENT="Author's Name Goes Here"> <META NAME="DESCRIPTION" CONTENT="Description Goes Here"> <META NAME="KEYWORDS" CONTENT="Keyword Listing Goes Here"> <META NAME="OWNER" CONTENT="Editorial/JDC"> <META NAME="revision" CONTENT="@(#)index2.src 1.2 06/09/99 JDC"> <STYLE TYPE="text/css"> <!-- CODE {font-family: Courier, Monospace; font-size: 12pt} PRE {font-family: Courier, Monospace; font-size: 11pt} --> </STYLE> </HEAD> <!-- Start Body Insert--><BODY BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" ALINK="#FF0000" VLINK="#660066"><!-- End Body Insert--> <!-- Start PageTop Insert --><TD> <P> <TABLE BORDER="0" WIDTH="100%" CELLPADDING="0" CELLSPACING="0"> <TR VALIGN="TOP"> <TD WIDTH="100%"><IMG SRC="../../../../images/chiclet.row.gif" WIDTH="55" HEIGHT="18" ALT=""></TD> <TD ROWSPAN="4" ALIGN="RIGHT" WIDTH="152"><IMG SRC="../../../../images/developer.connection.header.gif"BORDER="0" HEIGHT="42" WIDTH="319"></TD> </TR> <TR VALIGN="TOP"> <TD BGCOLOR="#FFFFFF" HEIGHT="1" WIDTH="100%"> <IMG SRC="../../../../images/pixel.gif" HEIGHT="1" WIDTH="1" ALT=""></TD> </TR> <TR VALIGN="TOP"> <TD BGCOLOR="#CC9966" HEIGHT="1" WIDTH="100%"> <IMG SRC="../../../../images/pixel.gif" HEIGHT="1" WIDTH="1" ALT=""></TD> </TR> <TR VALIGN="TOP"><TD><IMG SRC="../../../../images/codesamples.gif" WIDTH="165" HEIGHT="22" ALT="Code Samples" BORDER=0></TD> </TR> </TABLE> </TD> </TR></TABLE><!-- End PageTop Insert --> <TABLE BORDER="0" CELLPADDING="0" CELLSPACING="0"> <TR> <TD> <FONT FACE="Verdana, Arial, Helvetica, sans-serif"> <!-- Template Version 2.0 --> <!-- ================== --> <!-- Start Main Content --> <!-- ================== --> <DIV ALIGN="RIGHT"> <FONT SIZE="3"><B>javax.swing</B></FONT><BR> <FONT SIZE="-1"><A HREF="../index.html">Code Samples Index</A></FONT> </DIV> <P> <FONT SIZE="-1"> These code examples and other materials are subject to Sun Microsystems, Inc. <a href="../../../../share/text/SMICopyright.html">Legal Terms</a> </FONT> <P> <H3>Firing Item Events</H3> An object wishing to fire item events must implement ItemSelectable. This example shows typical code that an object must implement to fire item events. When an item event is to be fired, fireItemEvent() should be called. <PRE> public class <font color="#0066ff"><I>ItemEvents</I></font> implements ItemSelectable { protected EventListenerList listenerList = new EventListenerList(); public Object[] getSelectedObjects() { return <font color="#0066ff"><I>selectedObjects</I></font>; } public void addItemListener(ItemListener l) { listenerList.add(ItemListener.class, l); } public void removeItemListener(ItemListener l) { listenerList.remove(ItemListener.class, l); } void fireItemEvent(int selected) { ItemEvent evt = null; // The next two lines should be in one line Object[] listeners = listenerList.getListenerList(); for (int i=0; i<listeners.length-2; i+=2) { if (listeners[i] == ItemListener.class) { if (evt == null) { // The next two lines should be in one line evt = new ItemEvent( this, ItemEvent.ITEM_STATE_CHANGED, this, selected); } // The next two lines should be in one // line. ((ItemListener)listeners[i+1]) .itemStateChanged(evt); } } } } </PRE> <P> <TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0> <TR><TD VALIGN=MIDDLE> <FONT SIZE="-1" FACE="Verdana, Arial, Helvetica, sans-serif"> Examplets<SUP><FONT SIZE="-2">TM</FONT></SUP> are Copyrighted 2000 by Addison-Wesley and Patrick Chan <BR>and are provided as a courtesy for your educational, non-commercial use.<BR><BR> Order this book from <a href="http://www.amazon.com/exec/obidos/ASIN/0201432994/xeo">Amazon</a> </FONT> </TD></TR></TABLE> <!-- ================ --> <!-- End Main Content --> <!-- ================ --> </FONT> </TD> </TR> </TABLE> <!-- Copyright Insert --><TABLE WIDTH="100%" CELLPADDING="0" BORDER="0" CELLSPACING="5"><TR> <TD VALIGN="TOP"> <P ALIGN=CENTER> [ This page was updated: <!-- new date --> 11-Sep-2000 ]</TD></TR><TR><TD BGCOLOR="#CCCCCC"><SPACER TYPE="BLOCK" HEIGHT="1" WIDTH="1"></TD></TR></TD></TR></TABLE><TR> <TR> <TD> <TABLE WIDTH="100%" CELLPADDING="0" BORDER="0" CELLSPACING="0"> <TR> <TD WIDTH="50%"> <FONT SIZE="-2" FACE="Verdana, Arial, Helvetica, sans-serif"> For more information on Java technology<BR> and other software from Sun Microsystems, call:<BR> </FONT> <FONT SIZE="-1" FACE="Verdana, Arial, Helvetica, sans-serif"> (800) 786-7638<BR></FONT> <FONT SIZE="-2" FACE="Verdana, Arial, Helvetica, sans-serif"> Outside the U.S. and Canada, dial your country's <A HREF="http://www.att.com/tollfree/international/dialguide/index.html">AT&T Direct Access Number</A> first.<BR> </FONT> </TD> <TD ALIGN="RIGHT" WIDTH="50%"> <A HREF="http://www.sun.com"><IMG SRC="../../../../images/lgsun.gif" width="64" height="30" border="0" ALT="Sun Microsystems, Inc."></A><BR> <FONT SIZE="-2" FACE="Verdana, Arial, Helvetica, sans-serif"> Copyright © 1995-2000 <A HREF="http://www.sun.com">Sun Microsystems, Inc.</A><BR> All Rights Reserved. <A HREF="../../../../share/text/termsofuse.html">Terms of Use</A>. <A HREF="http://www.sun.com/privacy/index.html">Privacy Policy</A>. </FONT> </TD> </TR> </TABLE> </TD> </TR> </TABLE></FORM><!-- End Copyright Insert --> </BODY> </HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -