本帖最后由 赵俊杰 于 2012-8-23 00:06 编辑
Dimension dem=Toolkit.getDefaultToolkit().getScreenSize();
int screenWidth=(int)dem.getWidth(),screenHeight=(int)dem.getHeight();
int thisWidth=500,thisHeight=600;
int thisX=(screenWidth-thisWidth)/2,thisY=(screenHeight-thisHeight)/2; //这句是关键。窗体X坐标=(屏幕宽度-窗体宽度)/2,Y坐标亦然。
this.setBounds(thisX,thisY,thisWidth,thisHeight); |