`
yingyingol
  • 浏览: 744708 次
文章分类
社区版块
存档分类
最新评论

java 连连看,正在完善中……

 
阅读更多

package guiGame;

import javax.swing.JFrame;
import javax.swing.SwingUtilities;

public class GameMain
{
/**
* @param args
* 连连看游戏,Java版
*/
public static void main(String[] args)
{
//Game game = new Game();
//game.show();
SwingUtilities.invokeLater(new Runnable()
{
@Override
public void run()
{
Game game = new Game();
game.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
game.setVisible(true);
}});
}
}

package guiGame;

/**游戏主界面
* author javaalpha

* date 2009年5月5日10:32:09
*/

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.Label;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.border.BevelBorder;
import javax.swing.border.Border;

@SuppressWarnings("serial")
public class Game extends JFrame implements ActionListener
{
Game()
{
this.initialize();
}

private JButton set = new JButton("设 置");
private JButton help = new JButton("帮 助");
private JButton about = new JButton("关 于");
private JButton start = new JButton("开 始 游 戏");
private JButton tip = new JButton("游 戏 提 示");
private JButton bomb = new JButton("使 用 炸 弹");
private JButton again = new JButton("重 新 再 来");
private JButton exit = new JButton("退 出 游 戏");

private void initialize()
{
this.setSize(780, 500); // 将窗体的大小设定为780*500
this.setResizable(false); // 窗体不能改变大小
this.setTitle("Java 连连看"); // 设置标题
this.setLocationRelativeTo(null); // 设置窗口相对于指定组件的位置
// this.initMenuBar();

Border border = BorderFactory.createBevelBorder(BevelBorder.LOWERED,
new Color(45, 92, 162), new Color(43, 66, 97), new Color(45,
92, 162), new Color(84, 123, 200)); // 设置边框的颜色

JPanel toolBar = new JPanel();// 游戏菜单区
toolBar.setBackground(Color.white); // 设置背景颜色
toolBar.setBorder(border); // 设置边框的样式
toolBar.setPreferredSize(new Dimension(780, 40));// 设置大小
toolBar.setLayout(new FlowLayout(FlowLayout.LEFT));// 设置按钮为左对齐

toolBar.add(set);// 添加设置按钮
toolBar.add(help);// 添加帮助按钮
toolBar.add(about);// 添加关于按钮

set.addActionListener(this);// 添加设置事件
help.addActionListener(this);// 添加帮助事件
about.addActionListener(this);// 添加关于事件

JPanel actionPanel = new JPanel();// 用户交互区
actionPanel.setBackground(Color.yellow); // 设置背景颜色
actionPanel.setBorder(border); // 设置边框的样式
actionPanel.setPreferredSize(new Dimension(160, 410));// 设置大小

actionPanel.add(start);// 添加开始游戏按钮
actionPanel.add(tip);// 添加游戏提示按钮
actionPanel.add(bomb);// 添加使用按钮
actionPanel.add(again);// 添加重新再来按钮
actionPanel.add(exit);// 添加退出游戏按钮

start.addActionListener(this);// 添加开始游戏事件
tip.addActionListener(this);// 添加游戏提示事件
bomb.addActionListener(this);// 添加事件
again.addActionListener(this);// 添加重新开始事件
exit.addActionListener(this);// 添加退出游戏事件

JPanel contentPanel = new JPanel();// 用户游戏区
contentPanel.setBackground(Color.blue); // 设置背景颜色
contentPanel.setBorder(border); // 设置边框的样式
contentPanel.setLayout(new GridLayout());//设置布局样式
contentPanel.setPreferredSize(new Dimension(620, 410));// 设置大小

//contentPanel.add(new JButton("a"));
//contentPanel.add(new JButton("a"));
//contentPanel.add(new JButton("a"));
//contentPanel.add(new JButton("a"));
//contentPanel.add(new JButton("a"));
//contentPanel.add(new JButton("a"));
//contentPanel.add(new JButton("a"));

JPanel bottomPanel = new JPanel();// 用户帮助区
bottomPanel.setBackground(Color.white);// 设置背景颜色
bottomPanel.setBorder(border);// 设置边框的样式
bottomPanel.setPreferredSize(new Dimension(780, 30));// 设置大小
bottomPanel.add(new Label("请点击开始按钮,开始游戏"));

this.getContentPane().add(toolBar, BorderLayout.NORTH);// 添加菜单板块
this.getContentPane().add(actionPanel, BorderLayout.EAST);// 添加右侧控制板块
this.getContentPane().add(contentPanel, BorderLayout.CENTER);// 添加中间核心区域板块
this.getContentPane().add(bottomPanel, BorderLayout.SOUTH);// 添加底部板块
}

@Override
public void actionPerformed(ActionEvent e)
{
if (e.getSource() == set)// 显示设置对话框
{

} else if (e.getSource() == help)// 显示帮助对话框
{

} else if (e.getSource() == about)// 显示关于对话框
{
String s = "作者:javaalpha copyright:2009-4-30";
JOptionPane.showMessageDialog(this, s, "关于",
JOptionPane.INFORMATION_MESSAGE);
return;
} else if (e.getSource() == start)// 开始游戏事件
{

} else if (e.getSource() == tip)// 提示事件
{

} else if (e.getSource() == bomb)// 事件
{

} else if (e.getSource() == again)// 重新开始事件
{

} else if (e.getSource() == exit)// 退出事件
{
System.exit(0);
}

}
}

简单的界面实习了,具体内容正在实现……

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics