package com.af1209.view;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.Timer;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import com.af1209.controller.MyTimerTask;
import com.af1209.modle.Info;
import com.af1209.modle.RussiaBlackUtile;
import com.af1209.modle.RussiaBlackUtileInterface;
/**
* 开始页面一般为在开始时在菜单选择
*
* @author chenyuyun
* @date 2012-11-5
*
*/
public class StartGameAreaPanel extends JPanel implements MouseListener{
private static final long serialVersionUID = 1L;
private Image imageMenu;
private JButton start;
private JButton set;
private JButton help;
private JButton exit;
private JButton easy;
private JButton midd;
private JButton hard;
private JButton returnB;
private Timer timer;
private Info info;
private Block[][] block;
private JFrame fatherFrame;
private JLabel jlable1;
private JLabel jlable2;
private JLabel jlable3;
private JLabel jlable4;
private JLabel jlable5;
private JDialog showHelp;
private JLabel jlable6;
private JButton returnButton;//返回主菜单页面
private JButton reStart;//重新开始
private JButton option;//主菜单
private JButton continueGame;//重新开始游戏
private RussiaBlackUtileInterface rUtile;
private JButton ziDongShangZhang;//方块是否自动上升
private JButton playMizic;//是否播放音乐
public StartGameAreaPanel( JPanel fatherJPanel, Timer timer,JFrame fatherFrame,Info info,Block[][] block) {
this.fatherFrame=fatherFrame;
this.info=info;
this.timer=timer;
this.block=block;
rUtile=new RussiaBlackUtile();
imageMenu = new ImageIcon("src/image/menuBg.jpg").getImage();
this.setLayout(null);// 布局设空后 再 自己确定位置
// 按钮添加图片
ziDongShangZhang=new JButton(new ImageIcon("src/image/zdsz.jpg"));
playMizic=new JButton(new ImageIcon("src/image/stopplay.jpg"));
start = new JButton(new ImageIcon("src/image/startbutton.jpg"));
set = new JButton(new ImageIcon("src/image/setbutton.jpg"));//
help = new JButton(new ImageIcon("src/image/help.jpg"));
exit = new JButton(new ImageIcon("src/image/exit.jpg"));
easy = new JButton(new ImageIcon("src/image/easy.jpg"));
midd = new JButton(new ImageIcon("src/image/midd.jpg"));
hard = new JButton(new ImageIcon("src/image/hart.jpg"));
returnB=new JButton(new ImageIcon("src/image/return.jpg"));
//主菜单
reStart=new JButton(new ImageIcon("src/image/restart.jpg"));
option=new JButton(new ImageIcon("src/image/option.jpg"));
continueGame=new JButton(new ImageIcon("src/image/continue.jpg"));
// 添加到 面板上
add(start);
start.setLocation(42, 150);
start.setSize(161, 33);
add(set);
set.setLocation(42, 210);
set.setSize(161, 33);
add(help);
help.setLocation(42, 270);
help.setSize(161, 33);
add(exit);
exit.setLocation(42, 330);
exit.setSize(161, 33);
//点击开始后的控件
easy.setLocation(42, 150);
easy.setSize(161, 33);
add(easy);
midd.setLocation(42, 210);
midd.setSize(161, 33);
add(midd);
hard.setLocation(42, 270);
hard.setSize(161, 33);
add(returnB);
returnB.setLocation(42, 330);
returnB.setSize(161, 33);
add(hard);
//主页面
reStart.setLocation(42, 150);
reStart.setSize(161, 33);
add(reStart);
continueGame.setLocation(42, 210);
option.setLocation(42, 270);
option.setSize(161, 33);
continueGame.setSize(161, 33);
add(continueGame);
add(option);
easy.setVisible(false);
midd.setVisible(false);
hard.setVisible(false);
returnB.setVisible(false);
//设置面板
ziDongShangZhang.setVisible(false);
ziDongShangZhang.setLocation(42, 150);
ziDongShangZhang.setSize(161, 33);
playMizic.setVisible(false);
playMizic.setLocation(42, 210);
playMizic.setSize(161, 33);
add(playMizic);
add(ziDongShangZhang);
//帮助面板
showHelp=new JDialog(fatherFrame,"帮助");
jlable1=new JLabel("功能键盘");
jlable2=new JLabel("快速向下:↓");
jlable3=new JLabel("旋转:↑");
jlable4=new JLabel("向左:←");
jlable5=new JLabel("向右:→");
jlable6=new JLabel("");
showHelp.add(jlable1);
showHelp.add(jlable2);
showHelp.add(jlable3);
showHelp.add(jlable4);
showHelp.add(jlable5);
showHelp.add(jlable6);
jlable1.setLocation(90, 30);
jlable1.setSize(100,30);
jlable2.setLocation(70, 70);
jlable2.setSize(100,30);
jlable3.setLocation(70, 100);
jlable3.setSize(100,30);
jlable4.setLocation(70, 130);
jlable4.setSize(100,30);
jlable5.setLocation(70, 160);
jlable5.setSize(100,30);
jlable6.setLocation(70, 200);
jlable6.setSize(100,30);
//放回主页面 按钮
returnButton=new JButton(new ImageIcon("src/image/rback.jpg"));
fatherJPanel.add(returnButton);
returnButton.setLocation(300, 500);
returnButton.setSize(115, 28);
returnButton.setVisible(false);
// 添加监听
ziDongShangZhang.addMouseListener(this);
playMizic.addMouseListener(this);
start.addMouseListener(this);
set.addMouseListener(this);
help.addMouseListener(this);
exit.addMouseListener(this);
easy.addMouseListener(this);
hard.addMouseListener(this);
midd.addMouseListener(this);
returnB.addMouseListener(this);
returnButton.addMouseListener(this);
reStart.addMouseListener(this);
reStart.setVisible(false);
option.addMouseListener(this);
option.setVisible(false);
continueGame.addMouseListener(this);
continueGame.setVisible(false);
reStart.setVisible(true);
reStart.setVisible(false);
this.timer = timer;
}
protected void paintComponent(Graphics g) {
g.drawImage(imageMenu, 0, 0, this.getWidth(), this.getHeight(), this);
}
@Override
public void mouseClicked(MouseEvent e) {
//点击开始后显示下级页面
if (e.getSource() == start) {
//将当前页面的按钮设为不可见
start.setVisible(false);
set.setVisible(false);
help.setVisible(false);
exit.setVisible(false);
//将下一界面显示
easy.setVisible(true);
midd.setVisible(true);
hard.setVisible(true);
returnB.setVisible(true);
}else if (e.getSource()==returnB){
start.setVisible(true);
set.setVisible(true);
help.setVisible(true);
exit.setVisible(true);
//将下一界面显示
easy.setVisible(false);
midd.setVisible(false);
hard.setVisible(false);
returnB.setVisible(false);
}
//开始下面子菜单的属性
else if(e.getSource()==easy){
//初始化参数
info.initGame();
rUtile.initBlocks(block);
info.setDifficulty(0);
info.setPlay(true);
info.setTimerTime(500);
this.timer=new Timer();
this.timer.schedule(new MyTimerTask(block, info, timer, fatherFrame), info.getTimerTime(), info.getTimerTime());
this.setSize(0, 0);
info.setShowStartPanel(false);
info.setShowReturnButton(true);
//初始化下个界面
reStart.setVisible(true);
option.setVisible(true);
continueGame.setVisible(true);
easy.setVisible(false);
midd.setVisible(false);
hard.setVisible(false);
returnButton.setVisible(info.isShowReturnButton());
fatherFrame.repaint();
fatherFrame.setFocusable(true);
fatherFrame.requestFocus();//将焦点移到主界面
}
else if(e.getSource()==midd){
//初始化参数
info.initGame();
rUtile.initBlocks(block);
info.setDifficulty(1);
info.setTimerTime(500);
info.setPlay(true);
this.timer=new Timer();
this.timer.schedule(new MyTimerTask(block, info, timer, fatherFrame), info.getTimerTime(), info.getTimerTime());
this.setSize(0, 0);
info.setShowReturnButton(true);
info.setShowStartPanel(false);
//初始化下个界面
reStart.setVisible(true);
option.setVisible(true);
continueGame.setVisible(true);
easy.setVisible(false);
midd.setVisible(false);
hard.setVisible(false);
returnButton.setVi
评论1
最新资源