Suppose I have a JTextfield . How does only this JTextfield implement an MVC architecture?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
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.