黑马程序员技术交流社区
标题:
拼图游戏1
[打印本页]
作者:
15044393192
时间:
2016-3-31 22:36
标题:
拼图游戏1
package cn.itcast.picture.ui;
import javax.swing.Icon;
import javax.swing.JButton;
/*
* 图片小方格类
*/
public class Cell extends JButton {
//带有图片的小方格
public Cell(Icon icon) {
super(icon);
//设置小方格大小
this.setSize(150, 150);
}
//带有图片并且带有文字的小方格
public Cell(String text, Icon icon) {
super(text, icon);
//设置小方格大小
this.setSize(150, 150);
this.setHorizontalTextPosition(CENTER);//文字水平居中显示
this.setVerticalTextPosition(CENTER);//文字垂直居中显示
}
//当前方格的移动
public void move(String direction){//上,下,左,右
switch (direction) {
case "UP":
this.setLocation(this.getBounds().x, this.getBounds().y - 150);
break;
case "DOWN":
this.setLocation(this.getBounds().x, this.getBounds().y + 150);
break;
case "LEFT":
this.setLocation(this.getBounds().x - 150, this.getBounds().y);
break;
case "RIGHT":
this.setLocation(this.getBounds().x + 150, this.getBounds().y);
break;
default://其他情况,不做移动处理
break;
}
}
}
作者:
风小筝
时间:
2016-4-1 09:23
加油加油加油
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/)
黑马程序员IT技术论坛 X3.2