1
2
3
4
5
6
7
8
9
10import java.applet.Applet;
11import java.awt.Button;
12import java.awt.Label;
13import java.awt.Color;
14import java.awt.GridLayout;
15import java.awt.event.ActionEvent;
16import java.awt.event.ActionListener;
17
18
19
20public
21class ModelViewController00
22 extends Applet
23{
24 Button control1, control2;
25
26 Label view;
27
28
29
30 public
31 void init() {
32
33
34
35
36 control1 = new Button("+1");
37 control1.setBackground(Color.orange);
38
39 control2 = new Button("-1");
40 control2.setBackground(Color.pink);
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
64 int i = Integer.valueOf(view.getText());
65 view.setText("" + (i+1));
66 }
67 }
68 );
69
70 control2.addActionListener
71 (new ActionListener()
72 {
73 public
74 void actionPerformed(ActionEvent e) {
75 int i = Integer.valueOf(view.getText());
76 view.setText("" + (i-1));
77 }
78 }
79 );
80 }
81
82}