質問編集履歴
2
追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -5,8 +5,6 @@
|
|
5
5
|
#ソース
|
6
6
|
|
7
7
|
```Java
|
8
|
-
|
9
|
-
|
10
8
|
|
11
9
|
import java.applet.*;
|
12
10
|
|
@@ -38,126 +36,70 @@
|
|
38
36
|
|
39
37
|
public class test extends Applet implements ActionListener{
|
40
38
|
|
41
|
-
|
39
|
+
int X = 75, Y = 30, W = 30, H = 50, K = 10 ;
|
42
40
|
|
43
|
-
|
41
|
+
Timer timer, timer2;
|
44
42
|
|
45
|
-
|
43
|
+
int x;
|
46
44
|
|
47
|
-
|
45
|
+
Button btn = new Button("スタート");
|
48
46
|
|
49
|
-
|
47
|
+
boolean btnClicked = false;
|
50
48
|
|
51
49
|
|
52
50
|
|
53
|
-
|
51
|
+
public void actionPerformed(ActionEvent e){
|
54
52
|
|
55
|
-
|
53
|
+
if (e.getSource() == timer2&&this.btnClicked==true){
|
56
54
|
|
57
|
-
x+= 2;
|
55
|
+
x+= 2;
|
58
56
|
|
59
|
-
if(x == 8){
|
57
|
+
if(x == 8){
|
60
58
|
|
61
|
-
x = 0;
|
59
|
+
x = 0;
|
60
|
+
|
61
|
+
}
|
62
62
|
|
63
63
|
}
|
64
64
|
|
65
|
-
|
65
|
+
if (e.getSource() == timer&&this.btnClicked==true){
|
66
66
|
|
67
|
-
|
67
|
+
|
68
68
|
|
69
|
-
timer2
|
69
|
+
timer2.start();
|
70
70
|
|
71
|
+
}
|
72
|
+
|
73
|
+
if (e.getSource()==this.btn){
|
74
|
+
|
75
|
+
this.btnClicked = true;
|
76
|
+
|
71
|
-
timer
|
77
|
+
this.timer.start();
|
78
|
+
|
79
|
+
}
|
80
|
+
|
81
|
+
repaint() ;
|
72
82
|
|
73
83
|
}
|
74
84
|
|
75
|
-
|
85
|
+
@Override
|
76
86
|
|
77
|
-
|
87
|
+
public void init(){
|
78
88
|
|
89
|
+
timer = new Timer(20, this);
|
90
|
+
|
91
|
+
timer2 = new Timer(2, this);
|
92
|
+
|
93
|
+
add(this.btn);
|
94
|
+
|
79
|
-
this.ti
|
95
|
+
this.btn.addActionListener(this);
|
80
96
|
|
81
97
|
}
|
82
98
|
|
83
|
-
repaint() ;
|
84
|
-
|
85
|
-
}
|
86
|
-
|
87
|
-
@Override
|
88
|
-
|
89
|
-
public void init(){
|
90
|
-
|
91
|
-
timer = new Timer(20, this);
|
92
|
-
|
93
|
-
add(this.btn);
|
94
|
-
|
95
|
-
this.btn.addActionListener(this);
|
96
|
-
|
97
|
-
}
|
98
99
|
|
99
100
|
|
101
|
+
省略
|
100
102
|
|
101
|
-
|
103
|
+
#追記
|
102
104
|
|
103
|
-
System.out.println("start");
|
104
|
-
|
105
|
-
}
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
public void stop(){
|
110
|
-
|
111
|
-
System.out.println("stop");
|
112
|
-
|
113
|
-
}
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
public void destroy(){
|
118
|
-
|
119
|
-
System.out.println("destroy");
|
120
|
-
|
121
|
-
}
|
122
|
-
|
123
|
-
public void update(Graphics g){
|
124
|
-
|
125
|
-
paint(g);
|
126
|
-
|
127
|
-
}
|
128
|
-
|
129
|
-
public void paint(Graphics g){
|
130
|
-
|
131
|
-
Dimension size = getSize();
|
132
|
-
|
133
|
-
Image back = createImage(size.width, size.height);
|
134
|
-
|
135
|
-
Graphics buffer = back.getGraphics();
|
136
|
-
|
137
|
-
buffer.clearRect(0, 0, 150, 150);
|
138
|
-
|
139
|
-
buffer.drawRect(X, Y, W, H);
|
140
|
-
|
141
|
-
|
105
|
+
timer2のインスタンスの生成をinitの中で行うことでアプレットは止まらなくなりました。
|
142
|
-
|
143
|
-
buffer.drawLine(X, Y+(K*2)-x, X+W, Y+(K*2)-x);
|
144
|
-
|
145
|
-
buffer.drawLine(X, Y+(K*3)-x, X+W, Y+(K*3)-x);
|
146
|
-
|
147
|
-
buffer.drawLine(X, Y+(K*4)-x, X+W, Y+(K*4)-x);
|
148
|
-
|
149
|
-
buffer.drawLine(X, Y+(K*5)-x, X+W, Y+(K*5)-x);
|
150
|
-
|
151
|
-
g.drawImage(back, 0, 0, this);
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
}
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
}
|
162
|
-
|
163
|
-
```
|
1
追加
test
CHANGED
File without changes
|
test
CHANGED
File without changes
|