Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

MVC in Java Text Component

 
krishna prasad gunasekaran
Ranch Hand
Posts: 158
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can you please explain th MVC architecture of java text component, and give the names of some of the classes of each tier.

krishna prasad
 
Kaydell Leavitt
Ranch Hand
Posts: 689
Eclipse IDE Firefox Browser Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The view is the JTextComponent (which is an abstract class so you'd use a JTextField or a JTextArea or a JPane) this is the view because the JTextComponent is the class that draws what is viewable in the window.

The model is the Document object that the JComponent has a reference to. The Document object is accessible by calling the method: JComponent.getDocument().

The controller is embedded in Swing. The Swing controller calls your listeners as needed once your listeners are registered with the Swing controllers.

The software that I'm working on has a second MVC architecture that I built on top of the Java API.

In this higher-level MVC, I consider the window as a whole as my view.

I consider my Model object as my model. My model object is merely a collection of field models.

I still consider Swing to be the controller, but at the higher-level, I let Swing work automatically once it is set up and only respond to higher-level events that are applicable to the entire window such as "Save".

Kaydell
[ May 19, 2007: Message edited by: Kaydell Leavitt ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic