1.创建一个窗口的实验代码
package 创建窗口;
import java.awt.Color;
import javax.swing.JFrame;
public class JFrameDemo01 {
public static void main(String[] args) {
// TODO Auto-generated method stub
JFrame f=new JFrame("窗口");
f.setSize(500,300);
f.setBackground(Color.WHITE);
f.setLocation(400,400);
f.setVisible(true);
}
}
运行结果
2.设置窗口内容
package 创建窗口;
import javax.swing.JFrame;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Point;
import java.awt.Font;
import javax.swing.JLabel;
public class JFrameDemo2 {
public static void main(String[] args){
JFrame f=new JFrame("Welcome");
Font fnt=new Font("Serief",Font.ITALIC+Font.BOLD,28);
JLabel lab=new JLabel("晚安",JLabel.CENTER);
lab.setFont(fnt);
f.add(lab);
Dimension d=new Dimension();
d.setSize(300,400);
f.setSize(d);
f.setBackground(Color.WHITE);
Point p=new Point(400,100);
f.setLocation(p);
f.setVisible(true);
}
}
运行结果
原文:https://www.cnblogs.com/LuZhenYu/p/11823227.html