IntelliJ Java IDE
The moose likes Swing / AWT / SWT / JFace and the fly likes problem in ActionListener Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT / JFace
Reply Bookmark "problem in ActionListener" Watch "problem in ActionListener" New topic
Author

problem in ActionListener

sagar khana
Greenhorn

Joined: Jan 15, 2012
Posts: 15
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: 2688

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: 15
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
 
 
subject: problem in ActionListener
 
Threads others viewed
problem in erasing panel
11 K&B questions. Question 3
getText() is not working?
question from KB Book
Question on static
IntelliJ Java IDE