• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

problem in ActionListener

 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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

 
Bartender
Posts: 4568
9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic