首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 软件管理 > 软件架构设计 >

Java中GUI的展示在屏幕中间的方法

2012-10-24 
Java中GUI的显示在屏幕中间的方法所需要的类:GraphicsEnvironment,Point。用到的方法有:GraphicsEnvironmen

Java中GUI的显示在屏幕中间的方法
所需要的类:GraphicsEnvironment,Point。用到的方法有:GraphicsEnvironment类中的静态方法getLocalGraphicsEnvironment()方法、getCentPoint()方法。

首先,我们要创建一个GraphicsEnvironment类的对象。

GraphicsEnvironment ge=GraphicsEnvironment.getLocalGraphicsEnvionment();

然后使用对象ge来获取屏幕的中心点:

Point p=ge.getCenterPoint();

然后调用GUI的setLocation方法来定义GUI的显示位置:

setLocation(p.x-XSize/2,p.y-YSize/2);

其中XSize表示GUI组件的宽,YSize表示GUI组件的高!


热点排行