我想在打开另一个帧时关闭我的homeScreen
帧
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是一个扩展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 );