其他分享
首页 > 其他分享> > JFrame和Container的使用

JFrame和Container的使用

作者:互联网

1.JFrame:

 1 public static void init() {
 2         JFrame frame = new JFrame("JFrame窗口");
 3         frame.setVisible(true);
 4         frame.setBounds(100,100,200,200);
 5         
 6         //设置文字
 7         JLabel label = new JLabel("JFrame系列");
 8         frame.add(label);
 9         
10         //文本标签居中,设置水平对齐
11         label.setHorizontalAlignment(SwingConstants.CENTER);
12         
13         //关闭事件
14         frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
15     }

 

2.Container:

1 class MyJframe2 extends JFrame{
2     public void init() {
3         this.setBounds(10,10,200,300);
4         this.setVisible(true);
5         
6         Container container = this.getContentPane();
7         container.setBackground(Color.blue);
8     }
9 }

 

标签:200,JFrame,Container,10,frame,label,使用
来源: https://www.cnblogs.com/jue1e0/p/16123128.html