java扫雷项目_java 扫雷游戏源码案例项目

代码如下import java.awt.*;import javax.swing.*;//图形计数器JCounter三位class JCounter extends JPanel {        private static final long serialVersionUID = 1L;        private ImageIcon [] numSet = { new ImageIcon("image/c0.gif"), new ImageIcon("image/c1.gif"),                                             new ImageIcon("image/c2.gif"), new ImageIcon("image/c3.gif"),                                             new ImageIcon("image/c4.gif"), new ImageIcon("image/c5.gif"),                                             new ImageIcon("image/c6.gif"), new ImageIcon("image/c7.gif"),                                             new ImageIcon("image/c8.gif"), new ImageIcon("image/c9.gif"),

};        private JButton [] counter = { new JButton(numSet[0]), new JButton(numSet[0]), new JButton(numSet[0])};        private int counterNum;        private Insets space;        public JCounter() {                this(0);

}        public JCounter(int num) {                super();

setSize(23, 39);

space = new Insets(0,0,0,0);                this.counterNum = num;                for (int i=0; i

counter[i].setSize(13,23);

counter[i].setMargin(space);

add(counter[i]);

}

this.setVisible(true);

resetImage();

}

public int getCounterNum() {

return(counterNum);

}

private void setCounterNum(int num){                this.counterNum = num;

}

private void resetImage() {                int ones, tens, hundreds;

ones = counterNum % 10 ;

tens = counterNum % 100/10;

hundreds = (counterNum) % 1000/100;                this.counter[0].setIcon(numSet[hundreds]);                this.counter[1].setIcon(numSet[tens]);                this.counter[2].setIcon(numSet[ones]);

}

public void resetCounter(int num) {

setCounterNum(num);

resetImage();                this.repaint();

}        public static void main(String[] args) {

JFrame jf = new JFrame("Test");

jf.setSize(23,39);

JCounter jc = new JCounter();

jf.setContentPane(jc);

jf.show();

jc.resetCounter(394);

}

}

效果图

261122f57b7dcfd45299fb9ad0d544e4.png

原文:http://9888731.blog.51cto.com/9878731/1610957

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值