此拼图游戏是九宫格,图片是提前分割好的,未涉及自动分割图片算法。废话不说,代码如下:
package com.ctgu;
import java.awt.BorderLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
public class PaintGame extends JFrame implements ActionListener{
private JLabel jLabel;
private JButton jButton1,jButton2;
JPanel topPanel,dommPanel,centerPanel;
JButton[][] jButtons;
JButton[][] checkButtons;
JLabel labelTime,labelBu;
int num,sum,timeCount;
boolean boo;
private int blackrow;
private int blackcol;
private JButton blackButton;
String[][] strings = new String[4][4];
static Timer timer;
public static void main(String[] args) {
// TODO Auto-generated method stub
PaintGame pGame = new PaintGame();
timer = new Timer(1000,pGame);
timer.start();
/*Thread thread = new Thread(pGame);
thread.start();*/
pGame.setVisible(true);
}
public PaintGame(){
super();
this.setBounds(200, 200, 360, 525);
this.setTitle("拼图游戏");
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setResizable(false);
initGame();
}
public void initGame(){
num = 0;
sum = 30;
timeCount = 120000;
jLabel = new JLabel();
jButton1 = new JButton();
jButton2 = new JButton();
jButtons = new JButton[4][4];
checkButtons = new JButton[4][4];
labelTime = new JLabel();
labelBu