回答編集履歴
3
MVCパターンで考えましょう。
answer
CHANGED
@@ -49,3 +49,8 @@
|
|
49
49
|
// StartButtonを押せるようにする。
|
50
50
|
}
|
51
51
|
```
|
52
|
+
|
53
|
+
###
|
54
|
+
MVCパターンで考えましょう
|
55
|
+
---
|
56
|
+
アドバイスが中途半端になってしまいました。MVCパターンを導入しましょう。初期化やボタン制御はMVCパターンで考えてください。
|
2
MyActionListenerは一度しかnewできません。
answer
CHANGED
@@ -19,8 +19,18 @@
|
|
19
19
|
public class MyActionListener implements ActionListener{
|
20
20
|
public final StopWatch stopWatch = new StopWatch();
|
21
21
|
```
|
22
|
+
この場合、MyActionListenerは一度しかnewできません。
|
23
|
+
```Java
|
24
|
+
MyActionListener myListerner = new MyActionListener();
|
25
|
+
JButton btn1 = new JButton("StartButton");
|
26
|
+
btn1.addActionListener(myListerner);
|
27
|
+
JButton btn2 = new JButton("PauseButton");
|
28
|
+
btn2.addActionListener(myListerner);
|
29
|
+
JButton btn3 = new JButton("StopButton");
|
30
|
+
btn3.addActionListener(myListerner);
|
31
|
+
```
|
22
32
|
|
23
|
-
stop()は一度しか呼べないので使いません。MyActionListenerで以下のメソッドがペアで呼ばれるようにします。
|
33
|
+
イベント処理です。stop()は一度しか呼べないので使いません。MyActionListenerで以下のメソッドがペアで呼ばれるようにします。
|
24
34
|
resume() は suspend() が呼ばれた後でなければ呼べない。
|
25
35
|
start() は reset() が呼ばれた後でなければ2回呼べない。
|
26
36
|
|
@@ -38,4 +48,4 @@
|
|
38
48
|
// PauseButton/StopButtonを押せなくする。
|
39
49
|
// StartButtonを押せるようにする。
|
40
50
|
}
|
41
|
-
```
|
51
|
+
```
|
1
stopWatch\.toString\(\)を修正
answer
CHANGED
@@ -9,7 +9,7 @@
|
|
9
9
|
StopWatch.toString()を使えば、hours:minutes:seconds.milliseconds 形式の表示になります。SimpleDateFormatは捨ててください。
|
10
10
|
|
11
11
|
```Java
|
12
|
-
String Time = stopWatch.toString();
|
12
|
+
String Time = MyActionListener.stopWatch.toString();
|
13
13
|
```
|
14
14
|
|
15
15
|
> 上記のWEBサイトでは初期化について触れていなかったため、出来ればそれも含めてアドバイスのほうをお願いします。
|