java拖动图片拼图_求教,我的这个拼图程序中的移动图片的改怎么做

该楼层疑似违规已被系统折叠 隐藏此楼查看此楼

public class button extends JPanel implements MouseListener, ActionListener {

/**

*

*/

private static final long serialVersionUID = 1L;

private JButton[] button;

private ImageIcon[] puzzlep;

private JButton kbbutton;

private static final String[] IMAGES = { "images/f-0.jpg",

"images/f-1.jpg", "images/f-2.jpg", "images/f-3.jpg",

"images/f-4.jpg", "images/f-5.jpg", "images/f-6.jpg",

"images/f-7.jpg", "images/f-8.jpg", "images/f-9.jpg",

"images/f-10.jpg", "images/f-11.jpg", "images/f-12.jpg",

"images/f-13.jpg", "images/f-14.jpg", "images/f-15.jpg",

"images/f-16.jpg", "images/f-17.jpg", "images/f-18.jpg",

"images/f-19.jpg", "images/f-20.jpg", "images/f-21.jpg",

"images/f-22.jpg", "images/f-23.jpg", "images/f-222.jpg" };

public button() {

this.setLayout(new GridLayout(5, 5));

puzzlep = new ImageIcon[IMAGES.length];

for (int i = 0; i < IMAGES.length; i++) {

puzzlep[i] = new ImageIcon(IMAGES[i]);

}

button = new JButton[25];

for (int i = 0; i < 25; i++) {

button[i] = new JButton();

button[i].setFocusable(false);

button[i].setIcon(puzzlep[i]);

button[i].setActionCommand(String.valueOf(i));

button[i].addActionListener(this);

this.add(button[i]);

}

//this.remove(button[24]);

//kbbutton = new JButton();

//this.add(kbbutton);

}

public void start() {

int length=25;

int[] shuffled = new int[length];

boolean[] bool = new boolean[length]; //the length must equals to length

Random rand = new Random();

int num = 0;

for(int i = 0; i < length;i++){

do{

num = rand.nextInt(length);

}while(bool[num]);

bool[num] =true;

shuffled[i] = num;

button[i].setIcon(puzzlep[shuffled[i]]);

}

}

public void yidong(){

}

@Override

public void mouseClicked(MouseEvent e) {

// TODO Auto-generated method stub

}

@Override

public void mousePressed(MouseEvent e) {

// TODO Auto-generated method stub

}

@Override

public void mouseReleased(MouseEvent e) {

// TODO Auto-generated method stub

}

@Override

public void mouseEntered(MouseEvent e) {

// TODO Auto-generated method stub

}

@Override

public void mouseExited(MouseEvent e) {

// TODO Auto-generated method stub

}

@Override

public void actionPerformed(ActionEvent e) {

// TODO Auto-generated method stub

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值