button1 = new JButton("Button 1");
button2 = new JButton("Button 2");
do I need two of the following, one for each button? If so, how do I distinguish the two events?
public void actionPerformed(ActionEvent e)
p.s. For future reference, we have a GUI forum where such question are more appropriate. you should probably mosey over there if you have more questions along these lines.
[ February 22, 2005: Message edited by: Layne Lund ]
Originally posted by Stan James:
I like a style where the event handlers are extremely small ... one line to call another method. If you get into the Model View Controller pattern that method might be on a controller object. Imagine the handlers for the File/Exit menu item and an Exit button. Each has one line that calls the same exitTheApplication() method.
I think this is one reason why Swing introduced the Action class. Actions provide a nice mechanism for sharing code between menus, buttons, and other GUI controls. In fact, the API is such that you only add a line of code to register an action with the control upon creation. You don't need any extra code (beside what is in the Action class itself) to handle the event.
[ February 24, 2005: Message edited by: Layne Lund ]