-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCgMain.java
More file actions
executable file
·81 lines (60 loc) · 1.74 KB
/
Copy pathCgMain.java
File metadata and controls
executable file
·81 lines (60 loc) · 1.74 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
/**
* CgMain: contains the Main method
*/
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.media.opengl.awt.GLCanvas;
import com.jogamp.opengl.util.Animator;
public class CgMain extends JApplet {
static int width = 1000;
static int height = 800;
static Animator animator;
public void init() {
// set window size
setSize(new Dimension(width, height));
// set canvas
CgCanvas canvas = new CgCanvas(width, height);
canvas.requestFocus();
GLCanvas glc = canvas.getGLCanvas();
animator = new Animator(glc);
// define the layout of window
JPanel panel = new JPanel();
panel.setLayout(new BorderLayout());
panel.add(glc, BorderLayout.CENTER);
Container container = this.getContentPane();
container.setLayout(new BorderLayout());
container.add(panel, BorderLayout.CENTER);
// set key and mouse listener
CgKeyListener mkl = new CgKeyListener(canvas, animator);
canvas.addKeyListener(mkl);
glc.addKeyListener(mkl);
CgMouseListener mml = new CgMouseListener(canvas, animator);
canvas.addMouseListener(mml);
glc.addMouseListener(mml);
MyScene.init();
}
public void start() {}
public void stop() {}
// main
public static void main(String[] args) {
JFrame frame = new JFrame("--- SHOOTING GAME ---");
frame.setSize(width, height);
CgMain cgmain = new CgMain();
cgmain.init();
frame.getContentPane().add(cgmain);
frame.setVisible(true);
cgmain.start();
frame.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
new Thread(new Runnable() {
public void run() {
animator.stop();
System.exit(0);
}
}).start();
}
});
}
}