Re: swing event model
On 9/18/2010 5:27 AM, xdevel1999 wrote:
If I have a button and a frame and I register an actionlistener with
that frame when I push the button the handler on
the frame via getSource know that button but if I register a
mouselistener with the frame it doesn't know the button
why???
Does java event model support event propagation (bubbling) or not? I'm
confused!
So if I have many buttons and wanted to register one listener only to
the frame and via the frame
handler know which buttons fire one event how can I do that?
the Java model isn't like javascript DOM event model?
No, Java Swing is nothing like JavaScript.
You are better off registering a different ActionListener for every
button, which kicks off the exact process that button is supposed to
kick off. That way you don't have a lot of "if (source == foo)" blocks.
Also note, that you can actually have an "Action" instance which defines
quite a bit. An "Action" can be added to a menu as an item, to a button
as a button, and to a toolbar. Each "Action" instance has an
actionPerformed method which gets called whenever the UI item is actuated.
<http://download.oracle.com/javase/6/docs/api/javax/swing/AbstractAction.html>
How-To:
<http://download.oracle.com/javase/tutorial/uiswing/misc/action.html>
--
Daniel Pitts' Tech Blog: <http://virtualinfinity.net/wordpress/>