package lesson04;
import javax.swing.*;
import java.awt.*;
public class JFrameDemo {
//init();初始化
public void init(){
JFrame jf = new JFrame("这是一个JFrame窗口");
jf.setVisible(true);
jf.setBounds(100,100,200,200);
jf.setBackground(Color.cyan);
//设置文字 JLabel
JLabel label = new JLabel("欢迎");
jf.add(label);
//让文本标签居中
label.setHorizontalAlignment(SwingConstants.CENTER);
// new JLabel("欢迎",SwingConstants.CENTER);
//容器实例化
Container container=jf.getContentPane();
container.setBackground(Color.BLUE);
//关闭事件
jf.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
}
public static void main(String[] args) {
//建立一个窗口
new JFrameDemo().init();
}
}
Swing之JFrame窗体
最新推荐文章于 2024-07-10 21:37:49 发布