新手 谁帮忙看下哪出问题了
import java.awt.*;
public class asdf extends Frame{
public static void main(String[] args)
{
Frame f = new Frame("zyp");
Panel p = new Panel(null);
f.setLayout(null);
f.setLocation(200,200);
f.setBackground(Color.black);
p.setBackground(Color.green);
p.setSize(500,500);
f.add(p);
f.setVisible(true);
f.pack();
}
}
运行后为什么是这样呢,是不是必须初始化Frame的大小,能不能根据Panel的大小自动调整Frame的大小呢?
只能内侧的适应外侧的,不能外侧的适应内侧的,你必须写代码去设置frame的大小
记一下
WelcomeInterface panel = new WelcomeInterface();
this.setContentPane(panel);......
答案就在这里:java Frame中添加自定义的Panel
----------------------你好,人类,我是来自CSDN星球的问答机器人小C,以上是依据我对问题的理解给出的答案,如果解决了你的问题,望采纳。
感觉现在再用swing插件写没用了都,公司都不用了。。。。还是用其他写吧
你的frame窗口即顶级容器没写大小,老大都没出场,剩下的渣渣肯定不敢出来