不多说,, 直接可以拷贝下面的东西, 然后记得把那个 BLOCK 的名字改成你自己的类名, 这个很关键哦,不然是错的可别怪我,呵呵~~ import .*; import .*; import .*; import .*; import .*; import .*; import .*; public class Block extends JPanel implements ActionListener,KeyListener // 应该是继承 JPanel { static Button but [] = new Button[6]; static Button noStop = new Button( " 取消暂停" ); static Label scoreLab = new Label( " 分数:" ); static Label infoLab = new Label( " 提示:" ); static Label speedLab = new Label( " 级数:" ); static Label scoreTex = new Label( "0" ); static Label infoTex = new Label( "" ); static Label speedTex = new Label( "1" ); static JFrame jf = new JFrame(); static MyTimer timer ; static ImageIcon icon = new ImageIcon( "resource/" ); static JMenuBar mb = new JMenuBar(); static JMenu menu0 = new JMenu( " 游戏" ); static JMenu menu1 = new JMenu( " 帮助" ); static JMenuItem mi0 = new JMenuItem( " 新游戏" ); static JMenuItem mi1 = new JMenuItem( " 退出" ); static JMenuItem mi1_0 = new JMenuItem( " 关于" ); static JDialog dlg_1 ; static JTextArea dlg_1_text = new JTextArea(); static int startSign = 0; // 游戏开始标志 0 未开始 1 开始 2 暂停 static String butLab [] ={" 开始游戏"," 重新开始"," 降低级数"," 提高级数"," 游戏暂停"," 退出游戏" }; static int game_body [][] = new int [19][10]; static int game_sign_x [] = new int [4]; // 用于记录 4 个方格的水平位置 static int game_sign_y [] = new int [4]; // 用于记录 4 个方格的垂直位置 static boolean downSign = false ; // 是否落下 static int blockNumber = 1; // 砖块的编号 static int gameScore = 0; // 游戏分数 static int speedMark = 1; public static void main(String args[]) { Block myBlock = new Block(); mb .add( menu0 ); mb .add( menu1 ); menu0 .add( mi0 ); menu0 .add( mi1 ); menu1 .add( mi1_0 ); jf .setJMenuBar( mb ); (); jf .add(myBlock); jf .setSize(565,501); jf .setResizable( false ); jf .setTitle( " 俄罗斯方块" ); jf .setIconImage( icon .getImage()); jf .setLocation(200,100); jf . show () ; timer = new MyTimer(myBlock); // 启动线程 timer .setDaemon( true ); timer .start(); tim
JAVA俄罗斯方块源代码 来自淘豆网m.daumloan.com转载请标明出处.