14.Swing 与JFrame

package GUI;

import javax.swing.*;
import java.awt.*;


// Swing 比 AWT 高级,这里的JFrame 可以直接关闭窗口
public class Test14_JFrame {
    public static void main(String[] args) {
        new MyJFrame().init();
    }
}

class MyJFrame extends JFrame{
    public void init(){
        setSize(100,200);
        //  setBackground(Color.red);  // Jrame,直接设置背景颜色是不行的,得需要容器。Frame 可以
        setVisible(true);
       // 获得一个容器,然后设置容器的颜色
        Container container=getContentPane();
        container.setBackground(Color.red);

        // 关闭窗口的操作
        setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    }
    }
}
posted @   被占用的小海海  阅读(15)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· AI 智能体引爆开源社区「GitHub 热点速览」
· 三行代码完成国际化适配,妙~啊~
· .NET Core 中如何实现缓存的预热?
点击右上角即可分享
微信分享提示