1 xem dum minh loi cua bai ni nha JAVA33 Thu Nov 08, 2012 7:51 pm
1101817
Vịt mới lớn
BQT xem giup dum minh bai ni nhe minh khong biet sua loi cua code nay nhu the nao BQT giup dum minh nhe thanks cac ban nhieu
- Code:
import java.awt.Color;
import java.awt.GridLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
public class bai001{
private JFrame frame;
public bai001(){
int i,j;
frame = new JFrame();
JButton bt[] = new JButton[10];
frame.setTitle("Excercise");
frame.setBounds(900,200,300,300);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLayout(new GridLayout(8,8));
for(i=0;i<8;i++)
for(j=0;j<8;j++){
int a=i+j;
if(a%2==0)
{
bt[a] = new JButton();
bt[a].setBackground(Color.WHITE);
frame.add(bt[a]);
}
else
{
bt[a] = new JButton();
bt[a].setBackground(Color.BLACK);
frame.add(bt[a]);
}
}
frame.setVisible(true);
}
public static void main(String[] args){
bai001 b1 = new bai001();
}
}