wood burning stoves 2.0*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Listeners in controller class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "Listeners in controller class" Watch "Listeners in controller class" New topic
Author

Listeners in controller class

Cecilia Anderson
Greenhorn

Joined: Nov 11, 2001
Posts: 13
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

Joined: Feb 25, 2002
Posts: 560
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

Joined: Nov 11, 2001
Posts: 13
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

Joined: Feb 05, 2001
Posts: 17249
    
    6

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 ]

Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Listeners in controller class
 
Similar Threads
writing good GUI code
JButtons should start Threads whit synchronized handling of a JTable model
naive questions about mvc
MVC or Moderate pattern for GUI?
Listener classes + javadoc