怎么控制java应用程序跳出窗口 在屏幕上的位置阿??

来源:百度知道 编辑:UC知道 时间:2024/06/04 22:04:37
为什么总是从最左上方跳出来呢??可不可以从屏幕的中间跳出阿

Toolkit tk = this.getToolkit();//得到窗口工具条
int width = 650;
int height = 500;
Dimension dm = tk.getScreenSize();

构造方法里:
this.setSize(width,height);//设置程序的大小
this.setLocation((int)(dm.getWidth()-width)/2,(int)(dm.getHeight()-height)/2);//显示在屏幕中央
setLocation("",""),直接给两个值,就会出现在相应的位置,你自己试试

用setBounts方法
有4个参数
setBounts(窗口左上角横坐标,窗口左上角纵坐标,窗口宽,窗口高);
这是我的一个Dialog
Logondialog lo = new Logondialog(null,"登录",true);
lo.setBounds(380,290,300,240);
lo.setVisible(true);