• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Listeners in controller class

 
Cecilia Anderson
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi!
My ambition is to put all listeners in a ClientController class but I can�t see how to do it.
Normally I would have the listener as an inner class like this:
public class ClientView{
xxxxx
button.addMouseListener(new SearchListener());
xxxxx
class SearchListener extends MouseInputAdapter{
public void mouseClicked(MouseEvent me){
button.setEnabled(false);
}
}
}
How can I put all listeners in the ClientController and how should the controller get access to the "button" ??? Does anybody have a good example??
//Cecilia
 
Sai Prasad
Ranch Hand
Posts: 560
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In your code, move the SearchListener to the controller from the view class and call setSearchListener(new SearchListener()) defined in the view from the controller constructor.
 
Cecilia Anderson
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hmm...still don�t get it
Should I put the SearchListener class as an inner class in the ClientController?? And if I do...
what should I add to button.addMouseListener(??)

Could you give an example??
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, in your GUI class, the view you have a method like such.
fileExit is a MenuItem

Then in your Controller to hook into the GUI so that it can run a method when an action occurs you have the following code.
frontEnd is the reference to the instance of the GUI class that the controller has.

Hope that helps
Mark
[ May 10, 2002: Message edited by: Mark Spritzler ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic