i.e avoiding to repeat same code for every button.
Is that possible to do and if so , how?

Regards
stab

September 27th, 2011, 03:32 AM

Sean4u

Re: Is it possible to use same event code for several objects?

You create a single ActionListener (it's an interface, so it's common for people to implement the interface in their application-containing JFrame for example) and Event.getSource() has a reference to which control the event is 'for'.

Post code in code tags.

September 27th, 2011, 03:49 AM

namhm

Re: Is it possible to use same event code for several objects?

Quote:

i.e avoiding to repeat same code for every button.
Is that possible to do and if so , how?

Yes, it is possible as Sean4u suggested. It would be fine if the code to handle the event is same for all buttons, otherwise you will come up with many if-else statements to identify which button is clicked, which may make the code looks messy.

September 27th, 2011, 04:12 AM

stab

Re: Is it possible to use same event code for several objects?

Actually I would like to do this for smartgwt imgbuttons, but I don't understand how to add an ActionListener.
I have a class:
public class gwtMap extends Composite {
and when I add, implements ActionListener, I'm supposed to import ava.awt.event.ActionListener but I guess I shouldn't mix awt and gwt.

September 27th, 2011, 12:12 PM

namhm

Re: Is it possible to use same event code for several objects?

Quote:

Originally Posted by stab

Actually I would like to do this for smartgwt imgbuttons, but I don't understand how to add an ActionListener.
I have a class:
public class gwtMap extends Composite {
and when I add, implements ActionListener, I'm supposed to import ava.awt.event.ActionListener but I guess I shouldn't mix awt and gwt.

I don't have experience in GWT, however I think there's an equivalent Action listener in GWT.