File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Swing / AWT / SWT and the fly likes MVC in Java Text Component Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "MVC in Java Text Component" Watch "MVC in Java Text Component" New topic

MVC in Java Text Component

krishna prasad gunasekaran
Ranch Hand

Joined: Jul 25, 2006
Posts: 158
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

have a great day,
krishna prasad
Kaydell Leavitt
Ranch Hand

Joined: Nov 18, 2006
Posts: 689

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".

[ May 19, 2007: Message edited by: Kaydell Leavitt ]
I agree. Here's the link:
subject: MVC in Java Text Component
jQuery in Action, 3rd edition