[求助]这个GUI界面为什么没有显示出正确的结果
我想显式以下的图形,但是没有实现,为什么?
Java code
package justdoit.gui;
import java.awt.*;
public class TestLayout {
public static void main(String[] args) {
Panel con_1 = new Panel();
Panel con_2 = new Panel();
Button b1 = new Button("BUTTON");
Button b2 = new Button("BUTTON");
con_1.setLayout(new GridLayout(2,1));
con_1.add(b1);
con_1.add(b2);
Button b3 = new Button("BUTTON");
Button b4 = new Button("BUTTON");
Button b5 = new Button("BUTTON");
Button b6 = new Button("BUTTON");
con_2.setLayout(new GridLayout(2,2));
con_2.add(b1);
con_2.add(b2);
con_2.add(b3);
con_2.add(b4);
Button b7 = new Button("BUTTON");
Button b8 = new Button("BUTTON");
Button b9 = new Button("BUTTON");
Button b0 = new Button("BUTTON");
Frame f = new Frame("fourLayout");
f.setLayout(new GridLayout(2,3));
f.add(b7);
f.add(con_1);
f.add(b8);
f.add(b7);
f.add(con_2);
f.add(b9);
f.pack();
f.setSize(400,300);
f.setVisible(true);
}
}
------解决方案--------------------import java.awt.*;
public class TestLayout {
public static void main(String[] args) {
Panel con_1 = new Panel();
Panel con_2 = new Panel();
Button b1 = new Button("BUTTON");
Button b2 = new Button("BUTTON");
con_1.setLayout(new GridLayout(2,1));
con_1.add(b1);
con_1.add(b2);
Button b3 = new Button("BUTTON");
Button b4 = new Button("BUTTON");
Button b5 = new Button("BUTTON");
Button b6 = new Button("BUTTON");
con_2.setLayout(new GridLayout(2,2));
con_2.add(b3);
con_2.add(b4);
con_2.add(b5);
con_2.add(b6);
Button b7 = new Button("BUTTON");
Button b8 = new Button("BUTTON");
Button b9 = new Button("BUTTON");
Button b0 = new Button("BUTTON");
Frame f = new Frame("fourLayout");
f.setLayout(new GridLayout(2,3));
f.add(b7);
f.add(con_1);
f.add(b8);
f.add(b9);
f.add(con_2);
f.add(b0);
f.pack();
f.setSize(400,300);
f.setVisible(true);
}
}
太粗心了