一、项目总览

  Java版小型打字游戏

二、Main方法

  

 1 package cn.game.demo;
 2 
 3 import javax.swing.JFrame;
 4 
 5 /*
 6  * 打字游戏
 7  */
 8 public class MyWord {
 9     public static void main(String[] args) {
10         JFrame frame =new JFrame("打字游戏");
11         /** 添加画纸类 */
12         MyWordPanel panel= new MyWordPanel();
13         frame.add(panel);
14         /** 线程关联    */
15         Thread t=new Thread(panel);
16         t.start();
17         /**键盘关联*/
18         panel.addKeyListener(panel);
19         //键盘焦点在画纸上
20         panel.setFocusable(true);
21         
22         //设置大小
23         frame.setSize(800, 600);
24         //关闭方法
25         frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
26         //设置可见
27         frame.setVisible(true);
28         //设置居中
29         frame.setLocationRelativeTo(null);
30     
31     }
32 }
View Code

相关文章:

  • 2021-11-26
  • 2022-12-23
  • 2022-12-23
  • 2021-09-27
  • 2021-11-06
  • 2021-12-19
  • 2021-11-05
  • 2021-10-15
猜你喜欢
  • 2021-06-23
  • 2021-04-10
  • 2022-12-23
  • 2021-08-20
  • 2022-02-09
  • 2021-09-06
相关资源
相似解决方案