A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© 15044393192 中级黑马   /  2016-3-31 22:36  /  713 人查看  /  1 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

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;
                }
        }
       
       
}

1 个回复

倒序浏览
加油加油加油
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马