This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach 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 Murach's Java Servlets and JSP this week in the Servlets 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: 4338
    
    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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: problem in ActionListener
 
Similar Threads
question from KB Book
11 K&B questions. Question 3
Question on static
getText() is not working?
problem in erasing panel