import java.awt.Toolkit;
import javax.swing.JFrame;
/**
* @作者 jd
* @日期 2006-11-5
* @项目名称 J2seCode
* @描述
* 初始化窗体出现位置为屏幕中心
*/
public class MiddleScreen extends JFrame{
private static final long serialVersionUID = 554795791498294538L;
public MiddleScreen(){
setTitle("测试");
setSize(300,300);
setDefaultCloseOperation(EXIT_ON_CLOSE);
//--------------------------关键代码--------------------------
Toolkit kit=Toolkit.getDefaultToolkit(); //需import java.awt.Toolkit;
int screenwidth=kit.getScreenSize().width;
int screenheight=kit.getScreenSize().height;
int frmwidth = this.getWidth();
int frmheight = this.getHeight();
this.setLocation(screenwidth/2-frmwidth/2,screenheight/2-frmheight/2);
//--------------------------关键代码--------------------------
}
public static void main(String[] args) {
new MiddleScreen().setVisible(true);
}
}
import javax.swing.JFrame;
/**
* @作者 jd
* @日期 2006-11-5
* @项目名称 J2seCode
* @描述
* 初始化窗体出现位置为屏幕中心
*/
public class MiddleScreen extends JFrame{
private static final long serialVersionUID = 554795791498294538L;
public MiddleScreen(){
setTitle("测试");
setSize(300,300);
setDefaultCloseOperation(EXIT_ON_CLOSE);
//--------------------------关键代码--------------------------
Toolkit kit=Toolkit.getDefaultToolkit(); //需import java.awt.Toolkit;
int screenwidth=kit.getScreenSize().width;
int screenheight=kit.getScreenSize().height;
int frmwidth = this.getWidth();
int frmheight = this.getHeight();
this.setLocation(screenwidth/2-frmwidth/2,screenheight/2-frmheight/2);
//--------------------------关键代码--------------------------
}
public static void main(String[] args) {
new MiddleScreen().setVisible(true);
}
}