资源描述:
《俄罗斯方块java代码》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、=================1======================packagerussia;/**控制面板类*/importjava.awt.*;importjava.awt.event.*;importjavax.swing.*;importjavax.swing.border.*;publicclassControlPanelextendsJPanel{privateTipBlockPaneltipBlockPanel;privateJPaneltipPanel,InfoPanel,buttonPanel;privatefinalJTex
2、tFieldlevelField,scoreField;privateJButtonplayButton,pauseButton,stopButton,turnHarderButton,turnEasilyButton;privateEtchedBorderborder=newEtchedBorder(EtchedBorder.RAISED,Color.WHITE,newColor(148,145,140));privateRussiaBlocksGamegame;privateTimertimer;publicControlPanel(finalRussi
3、aBlocksGamegame){this.game=game;/**图形界面部分*/setLayout(newGridLayout(3,1,0,4));tipBlockPanel=newTipBlockPanel();tipPanel=newJPanel(newBorderLayout());tipPanel.add(newJLabel("NextBlock:"),BorderLayout.NORTH);tipPanel.add(tipBlockPanel,BorderLayout.CENTER);tipPanel.setBorder(border);In
4、foPanel=newJPanel(newGridLayout(4,1,0,0));levelField=newJTextField(""+RussiaBlocksGame.DEFAULT_LEVEL);levelField.setEditable(false);scoreField=newJTextField("0");scoreField.setEditable(false);InfoPanel.add(newJLabel("Level:"));InfoPanel.add(levelField);InfoPanel.add(newJLabel("Scor
5、e:"));InfoPanel.add(scoreField);InfoPanel.setBorder(border);buttonPanel=newJPanel(newGridLayout(5,1,0,0));playButton=newJButton("Play");pauseButton=newJButton("Pause");stopButton=newJButton("Stop");turnHarderButton=newJButton("Turnharder");turnEasilyButton=newJButton("Turneasily");
6、buttonPanel.add(playButton);buttonPanel.add(pauseButton);buttonPanel.add(stopButton);buttonPanel.add(turnHarderButton);buttonPanel.add(turnEasilyButton);buttonPanel.setBorder(border);addKeyListener(newControlKeyListener());//添加add(tipPanel);add(InfoPanel);add(buttonPanel);/**添加事件监听
7、器*/playButton.addActionListener(newActionListener(){publicvoidactionPerformed(ActionEventevent){game.playGame();requestFocus();//让ControlPanel重新获得焦点以响应键盘事件}});pauseButton.addActionListener(newActionListener(){publicvoidactionPerformed(ActionEventevent){if(pauseButton.getText().equa
8、ls("Pause"))game.pauseGame