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);
}
}
}
简单的界面实习了,具体内容正在实现……
分享到:
相关推荐
好东西大家分享——JAVA连连看JAVA连连看JAVA连连看JAVA连连看JAVA连连看JAVA连连看JAVA连连看JAVA连连看JAVA连连看JAVA连连看JAVA连连看JAVA连连看JAVA连连看JAVA连连看JAVA连连看JAVA连连看JAVA连连看JAVA连连看
Java 练练看 含有源代码 文件形式:可运行jar文件 开发环境:Eclipse 强调一点:Java在读取jar自身文件时一定要注意后缀名的大小写。多次栽在这里,浪费时间。
Java 连连看 游戏代码,Java 连连看 游戏代码
基于Java的连连看实现代码
【Java毕业设计】基于Java的连连看游戏设计与实现(论文+答辩PPT+源代码+讲解视频).zip 【Java毕业设计】基于Java的连连看游戏设计与实现(论文+答辩PPT+源代码+讲解视频).zip 【Java毕业设计】基于Java的连连看...
用java写的连连看,有兴趣的大家大家看一下。。。
java连连看,自己设计java连连看,喜欢的朋友可以下载看看,功能有声音,刷新,提示,炸弹等~~
java连连看课程设计
简单的Java小游戏连连看,代码简单易懂,希望大家下载试玩,不足之处给予指正
java连连看 源代码 需要在classpath路径建立images文件夹,放入图片
java版连连看算法java版连连看算法java版连连看算法
基于java的连连看游戏设计和实现,基本功能包括:消除模块,重新开始模块,刷新模块,选择难度模块,计时模块。本系统结构如下: (1)消除模块: 完成连连看游戏消除动作的模块。 (2)重新开始模块: 完成...
JAVA连连看代码 ,欢迎大家前来分享。。 呵呵
java连连看源码,可供大家参阅。比较简单,只是作交流而已。
Java语言编写,有详细注释,用到了gui Java,Java,Java,Java,Java,Java,Java,Java,Java,Java,Java,Java,Java,Java,Java
Java连连看,欢迎大家学习,互相帮忙,一起进步!
Java连连看小游戏