Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
Dimension frameSize = frame.getSize();
if (frameSize.height > screenSize.height) {
frameSize.height = screenSize.height;
}
if (frameSize.width > screenSize.width) {
frameSize.width = screenSize.width;
}
frame.setLocation((screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2);
主要是setLocation方法!
Dimension frameSize = frame.getSize();
if (frameSize.height > screenSize.height) {
frameSize.height = screenSize.height;
}
if (frameSize.width > screenSize.width) {
frameSize.width = screenSize.width;
}
frame.setLocation((screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2);
主要是setLocation方法!
public class Test1 extends Applet{
......
final static Frame fr=new Frame();Test1{
DialDialog dialDialog;
dialDialog = new DialDialog(this.fr, "Dialog Tile");
dialDialog.setLocation(200,200);......
}
}试了试将setLocation放在DialDialog的构造函数中,去掉Test1中的,结果好用。
然后试一下setBounds(screenSize.width/4, screenSize.height/4,
screenSize.width/2, screenSize.height/2)
这样,Dialog离屏幕边距 1/4 屏幕宽高,Dialog本身高度和宽度占 1/2 屏幕宽高
把dialDialog定义为成员变量应该就可以了吧。
public class Test1 extends Applet{
......
final static Frame fr=new Frame();
DialDialog dialDialog;Test1{
dialDialog = new DialDialog(this.fr, "Dialog Tile");
dialDialog.setLocation(200,200);......
}
}