[英]closing an opened frame without closing the current
我想在打開另一個 Frame 時關閉我的homeScreen
Frame
public class MainClass {
public static void main(String[] args) {
JFrame homeScreen = new JFrame("HomeScreen");
homeScreen.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
EsPanel2 panelloPrimo = new EsPanel2();
homeScreen.add(panelloPrimo);
homeScreen.setBounds(0, 0, 690, 470);
homeScreen.setLocationRelativeTo(null);
homeScreen.setVisible(true);
}
}
Espanel2 是一個 class,它擴展了JPanel
並有一個按鈕,單擊它時,按鈕的ActionListener
會打開一個全新的 Frame。
單擊它時有一個按鈕,它通過按鈕的 ActionListener 打開一個全新的框架
您可以在ActionListener
中引用帶有邏輯的開放框架。 就像是:
// close existing frame
JButton button = (JButton)event.getSource();
Window window = SwingUtilities.windowForComponent(button);
window.dispose();
// create and show new frame
JFrame frame = new JFrame(...);
...
frame.setVisible( true );
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.