您的位置:首页 > 其它

一些有趣的图形界面

2015-11-20 16:29 169 查看
代码:

import java.awt.Color;
import java.awt.GridLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
public class MyFrame extends JFrame
{
public MyFrame()
{
setLayout(new GridLayout(8,8,0,0));
setTitle("鬼谷子的局");
setSize(800,800);
setVisible(true);
setDefaultCloseOperation(EXIT_ON_CLOSE);
JButton []Bu=new JButton [64];
for(int i=0;i<8;i++)
{
for(int j=0;j<8;j++)
{
Bu[i]=new JButton();
if((i+j)%2==0)
{
Bu[i].setBackground(Color.black);
Bu[i].setForeground(Color.blue);
Bu[i].setText((i+1)+"行"+(j+1)+"列");
}
else
{
Bu[i].setBackground(Color.white);
Bu[i].setForeground(Color.blue);
Bu[i].setText((i+1)+"行"+(j+1)+"列");
}
add(Bu[i]);
}
}
setVisible(true);
}
public static void main(String[] args)
{
MyFrame F=new MyFrame();
}

}


运行结果:

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: