Repository navigation
Expand file tree
/
Copy pathSimulacija.java
More file actions
71 lines (60 loc) · 1.5 KB
/
Copy pathSimulacija.java
File metadata and controls
71 lines (60 loc) · 1.5 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
package zad1;
import java.awt.BorderLayout;
import java.awt.Frame;
import java.awt.event.FocusAdapter;
import java.awt.event.FocusEvent;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
@SuppressWarnings("serial")
public class Simulacija extends Frame {
private Scena scena = new Scena();
public Simulacija() {
setTitle("Simulacija");
addComponents();
addListeners();
setLocation(500,200);
pack();
setResizable(false);
scena.createBufferStrategy(2);
scena.proceed();
setVisible(true);
}
private void addListeners() {
addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
terminate();
}
});
addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent e) {
if(e.getKeyCode() == KeyEvent.VK_ESCAPE) {
terminate();
}
else if(e.getKeyCode() == KeyEvent.VK_SPACE) {
if(scena.isRunning()) scena.pause();
else scena.proceed();
}
}
});
addFocusListener(new FocusAdapter(){
public void focusLost(FocusEvent e){
e.getComponent().requestFocus();
}
});
}
private void terminate() {
scena.interrupt();
dispose();
}
private void addComponents() {
setLayout(new BorderLayout());
add(scena,BorderLayout.CENTER);
}
public static void main(String[] args) {
new Simulacija();
}
}