• 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
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Himai Minh

Running a Method inside a ActionListener

 
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
author and iconoclast
Posts: 24204
44
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thankyou that worked perfectly :-D
 
Normally trees don't drive trucks. Does this tiny ad have a license?
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic