This week's book giveaway is in the Performance forum.
We're giving away four copies of The Java Performance Companion and have Charlie Hunt, Monica Beckwith, Poonam Parhar, & Bengt Rutisson on-line!
See this thread for details.
Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Running a Method inside a ActionListener

 
Samuel Woodhams
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hey,

The idea is that i have got an ActionListener that when the user presses on the button it checks a couple of varibles in the main method with if commands and it will eventually find one that is true. At which point it sets a String[]. The String[] is differrent everytime, however the oporation i want preformed on the String[] is the same everytime. i was wonderring if i could refferrence to a method in my code rather then just repeatting the same piece of code 7 times in my project.

this is a cut down version of thye code to show what im trying to achieve


thanks in advance
sam
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24211
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
From what I can see, that looks OK -- but why create a new "Genarate" object. Since actionPerformed already belongs to the Genarate class, you can call the method directly on the (implicit) object that's already doing the work; ie.,



In any case, what error are you getting?
 
Samuel Woodhams
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thankyou that worked perfectly :-D
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic