// A class (called VCThree) that acts as a controller as well as a viewer. // Barry Cornelius, 19 June 2000 import java.awt.event. ActionEvent; import java.awt.event. ActionListener; import javax.swing. Box; import javax.swing. BoxLayout; import javax.swing. JButton; import javax.swing. JLabel; import java.util. Observable; import java.util. Observer; public class VCThree implements ActionListener, Observer { private Model iModel; private JButton iJButton; private JLabel iJLabel; public VCThree(final Model pModel) { iModel = pModel; iJButton = new JButton("increment"); iJLabel = new JLabel("unset"); iJButton.addActionListener(this); } public Box getGUI() { final Box tBox = new Box(BoxLayout.Y_AXIS); tBox.add(iJButton); tBox.add(iJLabel); return tBox; } public void actionPerformed(final ActionEvent pActionEvent) { iModel.inc(); } public void update(final Observable pObservable, final Object pObject) { iJLabel.setText("" + iModel.get()); } }