import javax.swing.*;
import java.awt.*;
public class TestGridLayout{
public static void main(String args[]){
JFrame win=new JFrame("窗体");
win.setBounds(200,200,600,600);
win.setVisible(true);
JButton bSouth=new JButton("南"),
bNorth=new JButton("北"),
bEast =new JButton("东"),
bWest =new JButton("西");
JPanel bCenter=new JPanel();
win.add(bNorth,BorderLayout.NORTH);
win.add(bSouth,BorderLayout.SOUTH);
win.add(bEast,BorderLayout.EAST);
win.add(bWest,BorderLayout.WEST);
win.add( bCenter,BorderLayout.CENTER);
JButton b[];
bCenter.setLayout(new Gridlayout(3,3,5,5));//一直在这报错java.awt.Gridlayout cannot be resolved to a type b=new JButton[9];
for(int i=0;i<b.length;i++){
b[i]=new JButton(""+i);
bCenter.add(b[i]);
}
win.validate();
win.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
求高手解决,,,,,
import java.awt.*;
public class TestGridLayout{
public static void main(String args[]){
JFrame win=new JFrame("窗体");
win.setBounds(200,200,600,600);
win.setVisible(true);
JButton bSouth=new JButton("南"),
bNorth=new JButton("北"),
bEast =new JButton("东"),
bWest =new JButton("西");
JPanel bCenter=new JPanel();
win.add(bNorth,BorderLayout.NORTH);
win.add(bSouth,BorderLayout.SOUTH);
win.add(bEast,BorderLayout.EAST);
win.add(bWest,BorderLayout.WEST);
win.add( bCenter,BorderLayout.CENTER);
JButton b[];
bCenter.setLayout(new Gridlayout(3,3,5,5));//一直在这报错java.awt.Gridlayout cannot be resolved to a type b=new JButton[9];
for(int i=0;i<b.length;i++){
b[i]=new JButton(""+i);
bCenter.add(b[i]);
}
win.validate();
win.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
求高手解决,,,,,
你那一句中的 GridLayout 中的Layout 是写的layout 把l 改成大写的就好了.
你这里3 3 5 5指的是什么?
改成
GridLayout(3, 5);试试
GridLayout(int rows, int cols, int hgap, int vgap) rows行 cols 列, 列间距hgap, 行间距vgap
这不知道就查一下 API不就懂了么