Hi Guys,
I am quite experienced in programming with Java. I have though come accross a small problem, I don't know how to implement the MVC pattern. I understand the concepts of the MVC pattern and I was hoping that someone on this forum could help.

I have a model which is just a class that adds 2 integers together and returns the answer. The code is shown below.

public class Adder

public int add(int x, int y)
return x + y;

Now what I want to do is apply the MVC pattern to the above model. I want to have a Swing interface with 2 textboxes and an equals button which then displays the answer. How do I apply the MVC pattern?

Please don't try and mix the view and contoller in one - keep it separate.


Edited by happygeek: fixed formatting

10 Years
Discussion Span
Last Post by jwenting

And is there a particular reason you need a separate controller and don't want the view to serve that role? If you don't have the answer then you probably don't need to. Keep the model separate and let the view interact with it as needed.


I want a separate controller because I just want to see how its done. I'm guessing that in larger applications you need a separate controller & view? If you could just show me a sample I would be grateful. Thanks.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.