14.Swing 与JFrame

发布时间 2023-08-10 15:57:53作者: 被占用的小海海
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);
    }
}