Reputation: 5736
Suppose I have a JTextfield . How does only this JTextfield implement an MVC architecture?
Upvotes: 3
Views: 1139
Reputation: 324128
The Document is the Model.
Other than that a JTextField implements MVC the same as any other Swing component.
Upvotes: 3
Reputation: 921
All Java Swing components use MVC though its not always clear from the api. For each component there is a Controller, Model and View. JTextField, JButton, etc.. are all the Controllers. They also all support a getModel() which contains the state of the component. A lot of swing API pollute the controller api with convience methods so this is not always obvious. The text displayed in a JTextField is actually saved in the model. textField.getText() and textField.setText() are actually there for your convienence, what they really are doing is textField.getModel().getText() and textField.getModel().setText().
For the view there is a UI getComponentUI(). This is updated by propertyChanges fired from the Model. The ComponentUI is what lets different L&Fs be developed easily.
Upvotes: 4