MCPcopy Create free account
hub / github.com/TanaStudy/Java-Study / init

Method init

8. Demo/Java/src/main/LeetCode/Tetris/Main.java:40–75  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

38 }
39 /*游戏界面初始化函数*/
40 public void init() {
41 JPanel center = new JPanel(); //此面板为游戏核心区域
42 JPanel right = new JPanel(); //此面板为游戏说明区域
43 center.setLayout(new GridLayout(26, 12, 1, 1)); //给游戏核心区域划分行、列共26行,12列
44 for (int i = 0; i < grids.length; i++) {//初始化面板
45 for (int j = 0; j < grids[i].length; j++) {
46 grids[i][j] = new JTextArea(20, 20);
47 grids[i][j].setBackground(Color.WHITE);
48 grids[i][j].addKeyListener(this);// 添加键盘监听事件
49 //初始化游戏边界
50 if (j == 0 || j == grids[i].length - 1 || i == grids.length - 1) {
51 grids[i][j].setBackground(Color.PINK);
52 data[i][j] = 1;
53 }
54 grids[i][j].setEditable(false);// 文本区域不可编辑
55 center.add(grids[i][j]); //把文本区域添加到主面板上
56 }
57 }
58 //初始化游戏说明面板
59 right.setLayout(new GridLayout(4, 1));
60 right.add(new JLabel(" a : left d : right"));
61 right.add(new JLabel(" s : down w : change"));
62 right.add(label);
63 label1.setForeground(Color.RED);// 设置标签内容为红色字体
64 right.add(label1);
65 //把主面板和说明面板添加到窗体中
66 this.setLayout(new BorderLayout());
67 this.add(center, BorderLayout.CENTER);
68 this.add(right, BorderLayout.EAST);
69 running = true; //初始化running状态为true,表示程序运行即游戏开始
70 this.setSize(600, 850);// 设置窗体大小
71 this.setVisible(true);// 窗体可见
72 this.setLocationRelativeTo(null);// 设置窗体居中
73 this.setResizable(false);// 窗体大小不可改变
74 this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);// 释放窗体
75 }
76 /*主函数*/
77 public static void main(String[] args) {
78 Main m = new Main(); //创建Main对象,主要用于初始化数据

Callers 15

MainMethod · 0.95
cFunction · 0.45
cFunction · 0.45
MaFunction · 0.45
BaseThemeFunction · 0.45
RaphaëlThemeFunction · 0.45
HandRaphaëlThemeFunction · 0.45
DisplayFunction · 0.45
DisplayFunction · 0.45
merge.jsFile · 0.45
jquery.app.jsFile · 0.45
install.jsFile · 0.45

Calls 1

addMethod · 0.65

Tested by

no test coverage detected