關於 Modal 窗體
在 Swing 中只有 JDialog 可以設置為 Modal 窗體
在 JFrame 類中
public class MyModalFrame extends JFrame implements WindowListener
private JFrame frame = null;
private boolean modal = false;
private String title = null;
public MyModalFrame()
this(null
}
public MyModalFrame(JFrame frame)
this(frame
}
public MyModalFrame(JFrame frame
this(frame
}
public MyModalFrame(JFrame frame
super(title);
this
this
this
this
}
private void init()
if(modal)
frame
this
}
public void windowOpened(WindowEvent windowEvent)
}
public void windowClosing(WindowEvent windowEvent)
if(modal)
frame
}
public void windowClosed(WindowEvent windowEvent)
}
public void windowIconified(WindowEvent windowEvent)
}
public void windowDeiconified(WindowEvent windowEvent)
}
public void windowActivated(WindowEvent windowEvent)
}
public void windowDeactivated(WindowEvent windowEvent)
if(modal)
this
}
}
關於窗體啟動位置
有時候想要讓窗體啟動後在屏幕中間啟動
Dimension screenSize = Toolkit
Dimension size = frame
int x = (screenSize
int y = (screenSize
frame
在 Java
frame
Java API 文檔中對此方法描述如下
設置此窗口相對於指定組件的位置
在應用此方法時應該注意的一點是
From:http://tw.wingwit.com/Article/program/Java/hx/201311/26857.html