版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/weixin_41668995/article/details/81207583
JFrame窗体是一个容器。
import javax.swing.*;
import java.awt.*;
public class Example1 extends JFrame {
public void CreateJFrame(String title) {
JFrame jf = new JFrame(title);
Container container = jf.getContentPane();
JLabel jl = new JLabel("!!!");
jl.setHorizontalAlignment(SwingConstants.CENTER);
container.add(jl);
container.setBackground(Color.red);
jf.setVisible(true);
jf.setSize(200, 150);
jf.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
}
public static void main(String[] args) {
// TODO Auto-generated method stub
new Example1().CreateJFrame("创建一个JFrame窗体");
}
}