资源描述:
《java俄罗斯方块1源代码》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、importjava.awt.Button;importjava.awt.Canvas;importjava.awt.Color;importjava.awt.Dimension;importjava.awt.Frame;importjava.awt.Graphics;importjava.awt.GridLayout;importjava.awt.Insets;importjava.awt.Label;importjava.awt.Panel;importjava.awt.TextField;importjava.awt.event.ActionEvent;importjava.
2、awt.event.ActionListener;importjava.awt.event.KeyEvent;importjava.awt.event.KeyListener;importjava.awt.event.WindowAdapter;importjava.awt.event.WindowEvent;importjava.awt.event.WindowListener;//俄罗斯方块类publicclass俄罗斯方块1extendsFrame{privatestaticfinallongserialVersionUID=1L;publicstaticbooleanisP
3、lay=false;publicstaticintlevel=1,score=0;publicstaticTextFieldscoreField,levelField;publicstaticMyTimertimer;GameCanvasgameScr;publicstaticvoidmain(String[]argus){俄罗斯方块1ers=new俄罗斯方块1("俄罗斯方块游戏");WindowListenerwin_listener=(WindowListener)newWinListener();ers.addWindowListener(win_listener);}//俄
4、罗斯方块类的构造方法@SuppressWarnings("deprecation")俄罗斯方块1(Stringtitle){super(title);setSize(600,480);setLayout(newGridLayout(1,2));gameScr=newGameCanvas();gameScr.addKeyListener(gameScr);timer=newMyTimer(gameScr);timer.setDaemon(true);timer.start();timer.suspend();add(gameScr);PanelrightScr=newPanel();
5、rightScr.setLayout(newGridLayout(2,1,0,30));rightScr.setSize(120,500);add(rightScr);//MyPanelinfoScr=newMyPanel();infoScr.setLayout(newGridLayout(4,1,0,5));infoScr.setSize(120,300);rightScr.add(infoScr);//定义标签和初始值Labelscorep=newLabel("分数:",Label.LEFT);Labellevelp=newLabel("级数:",Label.LEFT);sco
6、reField=newTextField(8);levelField=newTextField(8);scoreField.setEditable(false);levelField.setEditable(false);infoScr.add(scorep);infoScr.add(scoreField);infoScr.add(levelp);infoScr.add(levelField);scorep.setSize(newDimension(20,60));scoreField.setSize(newDimension(20,60));levelp.setSize(newD
7、imension(20,60));levelField.setSize(newDimension(20,60));scoreField.setText("0");levelField.setText("1");//右边控制按钮窗体的布局MyPanelcontrolScr=newMyPanel();controlScr.setLayout(newGridLayout(5,1,0,5));rightScr.add(controlScr);//定义按钮playButtonp