一、项目总览
二、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 }