package com.ai.lesson04;
import javax.swing.*;
import java.awt.*;
public class JFrameDemo{
public void init(){
JFrame jf = new JFrame("这是一个JFrame窗口");
jf.setVisible(true);
jf.setBounds(100,100,200,200);
jf.setBackground(Color.cyan);
JLabel label = new JLabel("欢迎来到AI福说Java系列节目");
jf.add(label);
jf.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
}
public static void main(String[] args) {
new JFrameDemo().init();
}
}
package com.ai.lesson04;
import javax.swing.*;
import java.awt.*;
public class JFrameDemo02 {
public static void main(String[] args) {
new MyJframe2().init();
}
}
class MyJframe2 extends JFrame {
public void init(){
this.setBounds(10,10,200,300);
this.setVisible(true);
JLabel label = new JLabel("欢迎来到AI福说Java系列节目");
this.add(label);
label.setHorizontalAlignment(SwingConstants.CENTER);
Container container = this.getContentPane();
container.setBackground(Color.BLUE);
}
}