用户注册



邮箱:

密码:

用户登录


邮箱:

密码:
记住登录一个月忘记密码?

发表随想


还能输入:200字

大大胡    -  云代码空间

——

黑白棋界面

2016-12-08|581阅||

摘要:黑白棋界面

package 黑白棋界面;

import java.awt.Color;  
import java.awt.GridLayout;  
  
import javax.swing.JButton;  
import javax.swing.JFrame;  
import javax.swing.JLabel;  
  
public class ChessBord extends JFrame {  
    JButton[][] grids = new JButton[8][8];  
      
    public ChessBord() {  
        setLayout(new GridLayout(8, 8));  
          
        int count = 0;  
        for(int i = 0; i < grids.length; i++, count++) {  
            for(int j = 0; j < grids.length; j++) {  
                grids[i][j] = new JButton();  
                if(count % 2 == 0) {  
                    grids[i][j].setBackground(Color.WHITE);  
                    System.out.println("a");  
                } else {  
                    grids[i][j].setBackground(Color.BLACK);  
                }  
                add(grids[i][j]);  
                count++;  
            }  
        }  
    }  
      
    public static void main(String[] args) {  
        JFrame chessBorder = new ChessBord();  
        chessBorder.setTitle("国际象棋棋盘");  
        chessBorder.setLocation(300, 200);  
        chessBorder.setSize(400, 400);  
        chessBorder.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);  
        chessBorder.setVisible(true);  
    }  
}  


顶 0踩 0收藏
文章评论
    发表评论

    个人资料

    • 昵称: 大大胡
    • 等级: 初级程序员
    • 积分: 0
    • 代码: 0 个
    • 文章: 5 篇
    • 随想: 0 条
    • 访问: 0 次
    • 关注

    人气代码

      最新提问

        站长推荐