forked from bottleleung/Java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWormFrame.java
More file actions
43 lines (34 loc) · 937 Bytes
/
WormFrame.java
File metadata and controls
43 lines (34 loc) · 937 Bytes
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
package worm;
import java.awt.FlowLayout;
import javax.swing.JFrame;
import javax.swing.JLabel;
/**
* 贪吃蛇框架类
* @author Leslie Leung
*/
public class WormFrame extends JFrame {
private WormStage ws;
private JLabel label;
/**
* 构造方法
*/
public WormFrame() {
setSize(500, 500); //设置窗体大小
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLocationRelativeTo(null); //设置窗体于屏幕中央
setTitle("Worm"); //设置标题为Worm
setResizable(false); //不允许窗体缩放
setLayout(new FlowLayout()); //设置布局管理器
ws = new WormStage(); //新建舞台类对象
label = new JLabel("请按空格键控制游戏的开始和暂停,按方向键控制贪吃蛇运动方向");
add(label);
add(ws);
/* 监听贪吃蛇运动事件 */
addKeyListener(ws.getInnerInstanceOfKeyControl());
ws.addKeyListener(ws.getInnerInstanceOfKeyControl());
setVisible(true);
}
public static void main(String[] args) {
new WormFrame();
}
}