package example.haolei;
import java.awt.Dimension;
import java.awt.Toolkit;
import javax.swing.JFrame;
/**
* 窗体居中
* @author haolei
*/
public class FrameCenter extends JFrame {
public FrameCenter(){
super("frame center");
Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
this.setSize(400, 300);
this.setLocation(dim.width / 2 - this.getWidth() / 2, dim.height / 2 - this.getWidth() / 2);
this.setVisible(true);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public static void main(String[] args){
FrameCenter fc = new FrameCenter();
}
}