资源简介
java游戏华容道,具体见博客http://blog.csdn.net/simon_world

代码片段和文件信息
package game.medleyPicture;
import java.awt.BorderLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.Jframe;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.border.titledBorder;
public class MedleyGame extends Jframe {
private JLabel modelLabel;
private JPanel centerPanel;
private JButton emptyButton;
int num = 0;
public static void main(String[] args) {
try {
MedleyGame frame = new MedleyGame();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
//建立窗口构造方法
public MedleyGame() {
super();
setResizable(false);
settitle(“拼图游戏“);
setBounds(100 100 370 525);
setDefaultCloseOperation(Jframe.EXIT_ON_CLOSE);
//创建面板对象,并增加边框、布局
final JPanel topPanel = new JPanel();
topPanel.setBorder(new titledBorder(null ““ titledBorder.DEFAULT_JUSTIFICATION
titledBorder.DEFAULT_POSITION null null));
topPanel.setLayout(new BorderLayout());
getContentPane().add(topPanel BorderLayout.NORTH);//放于上方
//创建标签放原图
modelLabel = new JLabel();
modelLabel.setIcon(new ImageIcon(“image/“+ num+ “model.jpg“));
topPanel.add(modelLabel BorderLayout.WEST);
//在右侧加个面板,添加两个按钮
JPanel eastPanel = new JPanel();
topPanel.add(eastPanelBorderLayout.CENTER);
eastPanel.setLayout(new BorderLayout());
JButton nextButton = new JButton();
nextButton.setText(“下一张“);
nextButton.addActionListener(new NextButtonAction());
eastPanel.add(nextButtonBorderLayout.NORTH);
//创建按钮开局添加监听
final JButton startButton = new JButton();
startButton.setText(“开局“);
startButton.addActionListener(new StartButtonAction());
eastPanel.add(startButton BorderLayout.CENTER);
//初始化中心面板,设置边框,添加按钮
centerPanel = new JPanel();
centerPanel.setBorder(new titledBorder(null ““ titledBorder.DEFAULT_JUSTIFICATION
titledBorder.DEFAULT_POSITION null null));
centerPanel.setLayout(new GridLayout(4 0));
getContentPane().add(centerPanel BorderLayout.CENTER);
//初始化图片
String[][] exactnessOrder = order();
//按排列添加按钮,设置图片
for (int row=0; row<4; row++) {
for (int col=0; col<4; col++) {
final JButton button = new JButton();
button.setName(row+““+col);
button.setIcon(new ImageIcon(exactnessOrder[row][col]));
if (exactnessOrder[row][col].equals(“image/“+ num+“00.jpg“))
emptyButton = button;
button.addActionListener(new ImgButtonAction());
centerPanel.add(button);
}
}
}
//初始化图片
private String[][] order() {
String[][] exactnessOrder = new String[4][4];
for (int row=0; row<4; row++) {
for (int col=0; col<4; col++) {
exactnessOrder[row][col] = “image/“+ num+ row+ col+ “.jpg“;
}
}
return exactnessOrder;
}
//随机排列图片
private String[][] reorder() {
String[][] exactnessOrder = new String[4][4];
for (int row=0; row<4; r
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2014-12-07 21:04 MedleyPicture\
文件 301 2013-09-10 08:41 MedleyPicture\.classpath
文件 389 2013-09-10 08:41 MedleyPicture\.project
目录 0 2014-12-07 21:04 MedleyPicture\.settings\
文件 629 2013-09-10 08:41 MedleyPicture\.settings\org.eclipse.jdt.core.prefs
目录 0 2014-12-07 21:04 MedleyPicture\bin\
目录 0 2014-12-07 21:04 MedleyPicture\bin\game\
目录 0 2014-12-07 21:04 MedleyPicture\bin\game\medleyPicture\
文件 1885 2014-12-07 19:51 MedleyPicture\bin\game\medleyPicture\MedleyGame$ImgButtonAction.class
文件 2013 2014-12-07 19:51 MedleyPicture\bin\game\medleyPicture\MedleyGame$NextButtonAction.class
文件 1795 2014-12-07 19:51 MedleyPicture\bin\game\medleyPicture\MedleyGame$StartButtonAction.class
文件 4804 2014-12-07 19:51 MedleyPicture\bin\game\medleyPicture\MedleyGame.class
目录 0 2014-12-07 21:04 MedleyPicture\image\
文件 17518 2013-09-10 08:42 MedleyPicture\image\000.jpg
文件 19021 2013-09-10 08:42 MedleyPicture\image\001.jpg
文件 20713 2013-09-10 08:42 MedleyPicture\image\002.jpg
文件 17931 2013-09-10 08:42 MedleyPicture\image\003.jpg
文件 19225 2013-09-10 08:42 MedleyPicture\image\010.jpg
文件 20573 2013-09-10 08:42 MedleyPicture\image\011.jpg
文件 19567 2013-09-10 08:42 MedleyPicture\image\012.jpg
文件 19089 2013-09-10 08:42 MedleyPicture\image\013.jpg
文件 20164 2013-09-10 08:42 MedleyPicture\image\020.jpg
文件 21560 2013-09-10 08:42 MedleyPicture\image\021.jpg
文件 18501 2013-09-10 08:42 MedleyPicture\image\022.jpg
文件 18526 2013-09-10 08:42 MedleyPicture\image\023.jpg
文件 23971 2013-09-10 08:42 MedleyPicture\image\030.jpg
文件 24040 2013-09-10 08:42 MedleyPicture\image\031.jpg
文件 22988 2013-09-10 08:42 MedleyPicture\image\032.jpg
文件 21628 2013-09-10 08:42 MedleyPicture\image\033.jpg
文件 42730 2013-09-10 08:42 MedleyPicture\image\0model.jpg
文件 17987 2013-09-10 08:42 MedleyPicture\image\100.jpg
............此处省略88个文件信息
- 上一篇:Java实现微信支付demo
- 下一篇:java二维码生成与解析代码实现
相关资源
- JAVA 炸弹人
- java编写的泡泡堂炸弹人单机双人源码
- Java小游戏扑克牌
- java游戏之坦克大战
- java游戏合集
- 纯java游戏-植物大战僵尸源码
- 轩辕剑 天之痕 手机java游戏破解版
- 植物大战僵尸java游戏
- 战舰游戏设计课程报告+源码
- 基于Android系统的华容道游戏的开发
- java游戏详解,包括贪吃蛇等几十个游
- 基于android的华容道游戏的源代码
- 50个java游戏源代码.rar
- 华容道(项目源代码)
- 《Java游戏程序设计教程第二版》电子
- java 五子棋游戏
- java游戏之飞机大战
- 基于Java贪吃蛇游戏毕业论文
- JAVA游戏集(源码与打包文件)
- 安卓手机运行java程序的工具
- Java 仿超级玛丽的游戏完整代码
- java游戏之GIF转字符GIF
- java实现捕鱼达人
- Java游戏源码大礼包清明有爱强化版,
- 山寨版超级玛丽Java语言实现
- android应用开发app设计小游戏————
- java游戏保卫萝卜
- java华容道课程设计
- java捕鱼达人游戏(源码)
- Java游戏_角色类.rar
评论
共有 条评论