This week's giveaway is in the EJB and other Java EE Technologies forum.
We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes problem in ActionListener Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "problem in ActionListener" Watch "problem in ActionListener" New topic
Author

problem in ActionListener

sagar khana
Greenhorn

Joined: Jan 15, 2012
Posts: 21
i am having problem in this actionlistner while running first time it get called once and next time it called twice then four times and so on

here is code please give me any solution

thank you very much

Matthew Brown
Bartender

Joined: Apr 06, 2010
Posts: 4240
    
    7

Every time actionPerformed() is called it calls display(). And display() creates a load of new components and adds the ActionListener again. You really need to rethink your logic there. You ought to have some initialisation code that creates the components and adds event listeners, and then the event handlers should do the minimum amount of work needed to update the display.

In terms of design, I'd also be worried about a class that contains GUI code and database code, as these are completely separate concerns, but that's not your immediate problem.
sagar khana
Greenhorn

Joined: Jan 15, 2012
Posts: 21
Matthew Brown wrote:Every time actionPerformed() is called it calls display(). And display() creates a load of new components and adds the ActionListener again. You really need to rethink your logic there. You ought to have some initialisation code that creates the components and adds event listeners, and then the event handlers should do the minimum amount of work needed to update the display.

In terms of design, I'd also be worried about a class that contains GUI code and database code, as these are completely separate concerns, but that's not your immediate problem.


thank you i put addactionlistner outside and it works well
 
jQuery in Action, 2nd edition
 
subject: problem in ActionListener
 
Similar Threads
Question on static
problem in erasing panel
getText() is not working?
question from KB Book
11 K&B questions. Question 3