Java实现简易的拼图游戏
介绍:游戏共有五张图片可以选择,分成了4 X 4 十六个方格,点击开始就可以开始游戏。游戏运行的截图如下:

游戏结构:

代码如下:
MedleyGame.java类
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);//放于上方

这篇博客介绍了如何使用Java编程实现一个简单的4x4拼图游戏,提供了五张图片供玩家选择,并展示了游戏的运行截图。文章包含了游戏结构的概述以及关键代码链接。
最低0.47元/天 解锁文章
4471

被折叠的 条评论
为什么被折叠?



