• Post Reply Bookmark Topic Watch Topic
  • New Topic

Execute a method of an external class with a Buttonlistener

 
Jap Sni
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello there,

I have 3 classes here: Simulator, SimulatorView and ButtonListener.

Simulator simulates my program like the steps it takes and so.
SimulatorView contains things such as JFrame menus and buttons. (Ext. JFrame)
ButtonListener performs actions for each button. (Impl. ActionListener)

Here is my problem: I have put a button in the SimulatorView which the ButtonListener responds to, works fine.
But now I want to make the Listener call a method from Simulator if the button is pushed.

How should I do that

Thankies in advance.
 
pete stein
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your control class (ButtonListener) is going to have to have a reference to your model class (Simulator). So pass the listener / control class a reference to the simulator / model either via a parameter in its constructor or via a public method, public void setSimulator(Simulator s).
 
pete stein
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for having me waste my time by answering a question already answered in a cross-post!

Please read all the forum FAQ's next time before asking a question here, including this one: BeForthrightWhenCrossPostingToOtherSites
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jap Sni wrote:

Please check your private messages for an important administrative matter
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!