• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem with controller class

 
Pan Niko
Ranch Hand
Posts: 86
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 808
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Extremely basic but I hope it gives you the idea:

 
Pan Niko
Ranch Hand
Posts: 86
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 808
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 86
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic