package com.jia.lesson;
import javax.swing.*;
import java.awt.*;
public class JFrameDemo extends JFrame {
//初始化 init();
public void init(){
//JFrame jFrame = new JFrame();
this.setBounds(100,100,300,300);
this.setVisible(true);
//JFrame的颜色需要容器来设置
Container container =this.getContentPane();
container.setBackground(Color.GREEN);
//设置文字 JLabel
JLabel label = new JLabel("哈哈哈");
this.add(label);
//让文本标签居中
label.setHorizontalAlignment(SwingConstants.CENTER);
//关闭事件
this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
}
public static void main(String[] args) {
//建立一个窗口
new JFrameDemo().init();
}
}
Swing之JFrame窗体
最新推荐文章于 2023-06-21 14:10:59 发布