单机俄罗斯方块游戏制作心得(四)
2011-04-13 22:29
369 查看
下面说的是游戏工具界面的搭建。在MainFrame里定义下面属性
private GamePanel gamePanel;
//级别
private JLabel levelTextLabel = new JLabel("级别");
private JLabel levelLabel = new JLabel();
private Box levelTextBox = Box.createHorizontalBox();
private Box levelBox = Box.createHorizontalBox();
//分数
private Box scoreTextBox = Box.createHorizontalBox();
private Box scoreBox = Box.createHorizontalBox();
private JLabel scoreTextLabel = new JLabel("分数");
private JLabel scoreLabel = new JLabel();
//下一个
private Box nextTextBox = Box.createHorizontalBox();
private JLabel nextTextLabel = new JLabel("下一个");
//继续
private Box resumeBox = Box.createHorizontalBox();
private JLabel resumeLabel = new JLabel();
//暂停
private Box pauseBox = Box.createHorizontalBox();
private JLabel pauseLabel = new JLabel();
//开始
private Box startBox = Box.createHorizontalBox();
private JLabel startLabel = new JLabel();
//工具类
private JPanel toolPanel = new JPanel();
在MainFrame类里的构造器里添加下面代码来创造界面public MainFrame() {
this.currentLevel = 1;
this.gamePanel = new GamePanel(this);
BoxLayout toolPanelLayout = new BoxLayout(this.toolPanel, BoxLayout.Y_AXIS);
this.toolPanel.setLayout(toolPanelLayout);
this.toolPanel.setBorder(new EtchedBorder());
this.toolPanel.setBackground(Color.gray);
//分数
this.scoreTextBox.add(this.scoreTextLabel);
this.scoreLabel.setText(String.valueOf(this.score));
this.scoreBox.add(this.scoreLabel);
//级别
this.levelTextBox.add(this.levelTextLabel);
this.levelLabel.setText(String.valueOf(this.currentLevel));
this.levelBox.add(this.levelLabel);
//继续按钮
this.resumeLabel.setIcon(RESUME_ICON);
this.resumeLabel.setPreferredSize(new Dimension(3, 25));
this.resumeBox.add(this.resumeLabel);
//暂停按钮
this.pauseLabel.setIcon(PAUSE_ICON);
this.pauseLabel.setPreferredSize(new Dimension(3, 25));
this.pauseBox.add(this.pauseLabel);
//开始
this.startLabel.setIcon(START_ICON);
this.startLabel.setPreferredSize(new Dimension(3, 25));
this.startBox.add(this.startLabel);
//下一个
this.nextTextBox.add(this.nextTextLabel);
this.toolPanel.add(Box.createVerticalStrut(10));
this.toolPanel.add(scoreTextBox);
this.toolPanel.add(Box.createVerticalStrut(10));
this.toolPanel.add(scoreBox);
this.toolPanel.add(Box.createVerticalStrut(10));
this.toolPanel.add(levelTextBox);
this.toolPanel.add(Box.createVerticalStrut(10));
this.toolPanel.add(levelBox);
this.toolPanel.add(Box.createVerticalStrut(15));
this.toolPanel.add(this.resumeBox);
this.toolPanel.add(Box.createVerticalStrut(15));
this.toolPanel.add(this.pauseBox);
this.toolPanel.add(Box.createVerticalStrut(15));
this.toolPanel.add(this.startBox);
this.toolPanel.add(Box.createVerticalStrut(30));
this.toolPanel.add(this.nextTextBox);
this.blankBox.add(Box.createHorizontalStrut(99));
this.toolPanel.add(blankBox);
this.add(this.gamePanel, BorderLayout.CENTER);
this.add(this.toolPanel, BorderLayout.EAST);
this.setPreferredSize(new Dimension(349, 416));
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setLocation(350, 200);
this.setResizable(false);
this.setTitle("俄罗斯方块");
this.pack();
}
private GamePanel gamePanel;
//级别
private JLabel levelTextLabel = new JLabel("级别");
private JLabel levelLabel = new JLabel();
private Box levelTextBox = Box.createHorizontalBox();
private Box levelBox = Box.createHorizontalBox();
//分数
private Box scoreTextBox = Box.createHorizontalBox();
private Box scoreBox = Box.createHorizontalBox();
private JLabel scoreTextLabel = new JLabel("分数");
private JLabel scoreLabel = new JLabel();
//下一个
private Box nextTextBox = Box.createHorizontalBox();
private JLabel nextTextLabel = new JLabel("下一个");
//继续
private Box resumeBox = Box.createHorizontalBox();
private JLabel resumeLabel = new JLabel();
//暂停
private Box pauseBox = Box.createHorizontalBox();
private JLabel pauseLabel = new JLabel();
//开始
private Box startBox = Box.createHorizontalBox();
private JLabel startLabel = new JLabel();
//工具类
private JPanel toolPanel = new JPanel();
在MainFrame类里的构造器里添加下面代码来创造界面public MainFrame() {
this.currentLevel = 1;
this.gamePanel = new GamePanel(this);
BoxLayout toolPanelLayout = new BoxLayout(this.toolPanel, BoxLayout.Y_AXIS);
this.toolPanel.setLayout(toolPanelLayout);
this.toolPanel.setBorder(new EtchedBorder());
this.toolPanel.setBackground(Color.gray);
//分数
this.scoreTextBox.add(this.scoreTextLabel);
this.scoreLabel.setText(String.valueOf(this.score));
this.scoreBox.add(this.scoreLabel);
//级别
this.levelTextBox.add(this.levelTextLabel);
this.levelLabel.setText(String.valueOf(this.currentLevel));
this.levelBox.add(this.levelLabel);
//继续按钮
this.resumeLabel.setIcon(RESUME_ICON);
this.resumeLabel.setPreferredSize(new Dimension(3, 25));
this.resumeBox.add(this.resumeLabel);
//暂停按钮
this.pauseLabel.setIcon(PAUSE_ICON);
this.pauseLabel.setPreferredSize(new Dimension(3, 25));
this.pauseBox.add(this.pauseLabel);
//开始
this.startLabel.setIcon(START_ICON);
this.startLabel.setPreferredSize(new Dimension(3, 25));
this.startBox.add(this.startLabel);
//下一个
this.nextTextBox.add(this.nextTextLabel);
this.toolPanel.add(Box.createVerticalStrut(10));
this.toolPanel.add(scoreTextBox);
this.toolPanel.add(Box.createVerticalStrut(10));
this.toolPanel.add(scoreBox);
this.toolPanel.add(Box.createVerticalStrut(10));
this.toolPanel.add(levelTextBox);
this.toolPanel.add(Box.createVerticalStrut(10));
this.toolPanel.add(levelBox);
this.toolPanel.add(Box.createVerticalStrut(15));
this.toolPanel.add(this.resumeBox);
this.toolPanel.add(Box.createVerticalStrut(15));
this.toolPanel.add(this.pauseBox);
this.toolPanel.add(Box.createVerticalStrut(15));
this.toolPanel.add(this.startBox);
this.toolPanel.add(Box.createVerticalStrut(30));
this.toolPanel.add(this.nextTextBox);
this.blankBox.add(Box.createHorizontalStrut(99));
this.toolPanel.add(blankBox);
this.add(this.gamePanel, BorderLayout.CENTER);
this.add(this.toolPanel, BorderLayout.EAST);
this.setPreferredSize(new Dimension(349, 416));
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setLocation(350, 200);
this.setResizable(false);
this.setTitle("俄罗斯方块");
this.pack();
}
相关文章推荐
- 制作单机俄罗斯方块游戏心得(二)
- 制作单机俄罗斯方块游戏总结(一)
- 制作单机俄罗斯游戏心得(三)
- [前端 3]纯Js制作俄罗斯方块游戏
- 使用javascript制作俄罗斯方块游戏(2)
- 使用javascript制作俄罗斯方块游戏(3)
- [前端 3]纯Js制作俄罗斯方块游戏
- shell脚本制作俄罗斯方块游戏
- 使用javascript制作俄罗斯方块游戏(1)
- <Unity3D>使用Unity来制作俄罗斯方块游戏
- 使用Unity制作俄罗斯方块游戏
- Linux下shell脚本制作俄罗斯方块游戏
- 通过俄罗斯方块浅谈小游戏制作(序)
- 俄罗斯方块(flash游戏制作)
- C#编写的一个俄罗斯方块游戏
- 全面超越俄罗斯方块!立体的物理消除类游戏
- android小游戏制作心得(五)——游戏物体Body类和游戏世界World类
- js html5 css俄罗斯方块游戏再现
- Qt做的俄罗斯方块游戏
- 一个基于Yahoo UI的Ajax俄罗斯方块游戏