13_4.htm
来自「翁剀JAVA语言那门课程的教案 很多人都看多他的视频教程可惜没有ppt的教案」· HTM 代码 · 共 44 行
HTM
44 行
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<META NAME="Author" CONTENT="Weng Kai">
<META NAME="GENERATOR" CONTENT="Mozilla/4.01 [en] (Win95; I) [Netscape]">
<TITLE>Binding events dynamically</TITLE>
</HEAD>
<BODY>
<H2>
13.4 Binding events dynamically</H2>
<HR WIDTH="100%">
<BR>One of the benefits of the new AWT event model is flexibility. In the
old model you were forced to hard code the behavior of your program, but
with the new model you can add and remove event behavior with single method
calls. The following example demonstrates this:
<P>Case Study: <A HREF="case/DynamicEvents.java">DynamicEvents.java</A>
<P>The new twists in this example are:
<OL>
<LI>
There is more than one listener attached to each Button. Usually, components
handle events as multicast, meaning that you can register many listeners
for a single event. In the special components in which an event is handled
as unicast, you'll get a TooManyListenersException.</LI>
<LI>
During the execution of the program, listeners are dynamically added and
removed from the Button b2. Adding is accomplished in the way you've seen
before, but each component also has a removeXXXListener( ) method to remove
each type of listener. This kind of flexibility provides much greater power
in your programming. You should notice that event listeners are not guaranteed
to be called in the order they are added (although most implementations
do in fact work that way).</LI>
</OL>
<HR WIDTH="100%">
<DIV ALIGN=right><A HREF="13_5.htm">Next Page</A></DIV>
</BODY>
</HTML>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?