• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Problem with controller class

 
Ranch Hand
Posts: 86
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 808
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
reply
    Bookmark Topic Watch Topic
  • New Topic