wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes Problem with controller class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Problem with controller class" Watch "Problem with controller class" New topic
Author

Problem with controller class

Pan Niko
Ranch Hand

Joined: Mar 19, 2011
Posts: 86

Hello,

I trying to implement a program that is based on MVC model. Is my first time and I'll like some help. I have few classes that contains JButtons, JLabels, etc. those are my View. Also, I have a class that implements ActionListener and MouseListener and my View classes extends this Controller class. So, my obstacle is how I will connect each button or label in every class to this Controller class, so when button pressed to do something? Need a small sample code please.


Thank you
Pan_Niko
dennis deems
Ranch Hand

Joined: Mar 12, 2011
Posts: 808
Extremely basic but I hope it gives you the idea:

Pan Niko
Ranch Hand

Joined: Mar 19, 2011
Posts: 86

Thank you so much about the code, helps a lot. Need to have for each button I have in my program, or is multi-usable with this way? Also, if I have an empty JTextField in the ViewImpl and a button, and want when button pressed the JTextField filled with "Hello", how I will do this using MVC?

thank you

** Didn't notice this before, sorry


What is contained in those classes View and Model where you implement these classes?
dennis deems
Ranch Hand

Joined: Mar 12, 2011
Posts: 808
Pan Niko wrote:What is contained in those classes View and Model where you implement these classes?


They are interfaces. They might look something like this:

Pan Niko
Ranch Hand

Joined: Mar 19, 2011
Posts: 86

Hello,

Finally, decided to have one controller per each view class I have, and also, implements my view classes to Observer and my model class to Observable. By using interfaces with the way I'm working, is still helpful?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problem with controller class
 
Similar Threads
MVC question
client design
event handling for med sized MVC app
MVC pattern again - with one class per view
Who should open the data connection?