package com.user.interfaces;
import java.awt.Dimension;
import java.awt.Toolkit;
import javax.swing.JFrame;
public class UserInterFaces extends JFrame{
private String strname="程序";
public UserInterFaces() {
Dimension screensize = Toolkit.getDefaultToolkit().getScreenSize();
double Width=screensize.getWidth();
double Height=screensize.getHeight();
System.out.println(Width);
System.out.println(Height);
//设置大小
this.setSize(500, 300);
//窗体标题
this.setTitle(strname);
//窗体位置
this.setLocation((int)((Width-500)/2),(int)((Height-300)/2));
System.out.println((Width-500)/2);
System.out.println((Height-300)/2);
//关闭窗口即关闭程序
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//显示可视
this.setVisible(true);
}
public static void main(String[] args) {
UserInterFaces userInterFaces = new UserInterFaces();
}
}
如图所示