File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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

Listeners in controller class

Cecilia Anderson

Joined: Nov 11, 2001
Posts: 13
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{
button.addMouseListener(new SearchListener());
class SearchListener extends MouseInputAdapter{
public void mouseClicked(MouseEvent me){
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??
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

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

Joined: Feb 05, 2001
Posts: 17276

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
[ May 10, 2002: Message edited by: Mark Spritzler ]

Perfect World Programming, LLC - iOS Apps
How to Ask Questions the Smart Way FAQ
I agree. Here's the link:
subject: Listeners in controller class
It's not a secret anymore!