1
2
3
4
5
6import java.applet.Applet;
7import java.awt.Button;
8import java.awt.Label;
9import java.awt.Color;
10import java.awt.GridLayout;
11import java.awt.event.ActionEvent;
12import java.awt.event.ActionListener;
13
14
15
16public
17class ModelViewController0
18 extends Applet
19{
20 Button control1, control2;
21
22 int model;
23
24 Label view;
25
26
27
28 public
29 void init() {
30
31
32
33
34 control1 = new Button("+1");
35 control1.setBackground(Color.orange);
36
37 control2 = new Button("-1");
38 control2.setBackground(Color.pink);
39
40 model = 0;
41
42 view = new Label();
43 view.setAlignment(Label.CENTER);
44 view.setBackground(Color.gray);
45 view.setText("0");
46
47
48
49 setLayout(new GridLayout(3,1));
50
51 add(control1);
52 add(control2);
53 add(view);
54
55
56
57
58 control1.addActionListener
59 (new ActionListener()
60 {
61 public
62 void actionPerformed(ActionEvent e) {
63 ++model;
64 view.setText("" + model);
65 }
66 }
67 );
68
69 control2.addActionListener
70 (new ActionListener()
71 {
72 public
73 void actionPerformed(ActionEvent e) {
74 --model;
75 view.setText("" + model);
76 }
77 }
78 );
79 }
80
81}