import java.awt.*;public class FrameWithPanel extends Frame
{
public static void main(String[] args)
{
FrameWithPanel fr = new FrameWithPanel("Hello!"); fr.setSize(200, 200);
fr.setBackground(Color.blue);
fr.setLayout(new GridLayout(2, 1)); Panel pan = new Panel();
pan.setSize(200, 100);
pan.setBackground(Color.yellow);
pan.add(new Button("确定"));
fr.add(pan); fr.setVisible(true);
} public FrameWithPanel(String str)
{
super(str);
}
}这个程序如果这么写,显示的是上下两部分,再看下面这段程序import java.awt.*;public class FrameWithPanel extends Frame
{
public static void main(String[] args)
{
FrameWithPanel fr = new FrameWithPanel("Hello!"); fr.setSize(200, 200);
fr.setBackground(Color.blue);
fr.setLayout(new GridLayout(1, 2)); Panel pan = new Panel();
pan.setSize(100, 200);
pan.setBackground(Color.yellow);
pan.add(new Button("确定"));
fr.add(pan); fr.setVisible(true);
} public FrameWithPanel(String str)
{
super(str);
}
}我希望能够显示左右两部分,但为什么不是显示左右两部分呢?
解决方案 »
- java大牛们进来帮忙啊 openfile+extmail整合,用户信息同步
- ireport 报错(在线等。。。)
- 两个窗口的通信
- 这个do-while语句为什么条件没有满足循环却停止了?
- 在eclipse中启动tomcat如何设置tomcat内存大小?
- 分不多,没有可用分了,,ECLIPSE中为什么不可以指定新建的类继承自某一个类,我的只有一个object,,怎么回事?
- 菜鸟的蛋..刚开始学JAVA.有一点点C的基础..望给个自学的方向..
- 简单问题,如何在jtextField里用它的keyPressed事件里获取它的文本里的内容!
- help!有没有关于smalltalk的中文网站?
- 我要考SCJP,希望大家指教.强烈呼吁 考SCJP的同胞们联合起来!!!!!!!!!!!
- 能将这段Delphi函数转换成java代码吗?怎么转换??
- 关于运行.jar文件的问题
为什么要写成fr.setLayout(new GridLayout(0, 2)); 不明白,也没试。
而(2,1)和(2.0)几乎是完全一样了。就不会出现你的第一行的东西跑到第二行去的。