• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

problem in ActionListener

 
sagar khana
Greenhorn
Posts: 21
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4549
8
Java Netbeans IDE Scala
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 21
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic