-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathSafeFrame.java
More file actions
82 lines (68 loc) · 2.42 KB
/
Copy pathSafeFrame.java
File metadata and controls
82 lines (68 loc) · 2.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class SafeFrame extends Frame implements ActionListener, Context {
private TextField textClock = new TextField(60);
private TextArea textScreen = new TextArea(10, 60);
private Button buttonUse = new Button("금고 사용");
private Button buttonAlarm = new Button("비상 벨");
private Button buttonPhone = new Button("일반 통화");
private Button buttonExit = new Button("종료");
private State state = DayState.getInstance();
public SafeFrame(String title) {
super(title);
setBackground(Color.lightGray);
setLayout(new BorderLayout());
add(textClock, BorderLayout.NORTH);
textClock.setEditable(false);
add(textScreen, BorderLayout.CENTER);
textScreen.setEditable(false);
Panel panel = new Panel();
panel.add(buttonUse);
panel.add(buttonAlarm);
panel.add(buttonPhone);
panel.add(buttonExit);
add(panel, BorderLayout.SOUTH);
pack();
setVisible(true);
buttonUse.addActionListener(this);
buttonAlarm.addActionListener(this);
buttonPhone.addActionListener(this);
buttonExit.addActionListener(this);
}
@Override
public void actionPerformed(ActionEvent e) {
System.out.println(e.toString());
if(e.getSource() == buttonUse) {
state.doUse(this);
} else if (e.getSource() == buttonAlarm) {
state.doAlarm(this);
} else if (e.getSource() == buttonPhone) {
state.doPhone(this);
} else if (e.getSource() == buttonExit) {
System.exit(0);
} else {
System.out.println("?");
}
}
@Override
public void setClock(int hour) {
String clockstring = String.format("현재 시간은 %02d:00", hour);
System.out.println(clockstring);
textClock.setText(clockstring);
state.doClock(this, hour);
}
@Override
public void changeState(State state) {
System.out.println(this.state + "에서" + state + "으로 상태가 변화했습니다.");
this.state = state;
}
@Override
public void callSecurityCenter(String msg) {
textScreen.append("call! " + msg + "\n");
}
@Override
public void recordLog(String msg) {
textScreen.append("record ... " + msg + "\n");
}
}