Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

public class AnApplication { public static void main(String[] args) { AModel mod

ID: 3570429 • Letter: P

Question

public class AnApplication {

public static void main(String[] args) {

AModel model = new AModel();

AView view = new AView();

AController controller = new AController(model, view);

view.register(controller);

view.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

view.setSize(400, 300);

view.setVisible(true);

}

}

public class AView extends JFrame {

private JButton plusButton, minusButton;

private JLabel label;

public AView() {

super("Plus and Minus Buttons");

minusButton = new JButton("-");

label = new JLabel("0");

plusButton = new JButton("+");

setLayout(new FlowLayout());

add(minusButton);

add(label);

add(plusButton);

}

public void register(AController controller) {

minusButton.addActionListener(controller);

plusButton.addActionListener(controller);

}

public void displayValue(int value) {

label.setText("" + value);

}

}

public class AModel {

private int value;

public AModel() { value = 0; }

public int getValue() { return value; }

public void increment() { value++; }

public void decrement() { value--; }

}

public class AController implements ActionListener {

private AModel model;

private AView view;

public AController(AModel model, AView view) {

this.model = model;

this.view = view;

}

public void actionPerformed(ActionEvent event) {

    String buttonClicked = event.getActionCommand();

    System.out.println(buttonClicked);

    if(buttonClicked.equals("+"))

        model.increment();

    else if(buttonClicked.equals("-"))

        model.decrement();

    view.displayValue(model.getValue());

}

Draw a UML diagram showing the relationships between the classes in the application in the problem.

Explanation / Answer

contact on timacs12@gmail.com