lesson14-JFrameDemo

发布时间 2023-10-17 22:48:56作者: viking97816

 

 

 

 

 

package com.zym.lesson14;

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

public class JFrameDemo {

    public void init(){

       JFrame jFrame= new JFrame("lesson14-JFrameDemo");
        // jFrame.setBackground(Color.orange); 不起作用
        Container container=jFrame.getContentPane();
        container.setBackground(Color.orange);
        jFrame.setBounds(2,2,300,200);
       jFrame.setVisible(true);
       JLabel jLabel=new JLabel("我爱芳芳");
       //JFrame窗体也是一个顶级容器

       jFrame.add(jLabel);
    //   关闭事件
       jFrame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    }
    public static void main(String[] args) {
        new JFrameDemo().init();
    }
}