gpt4 book ai didi

java - 我想在新框架窗口出现时隐藏第一帧

转载 作者:行者123 更新时间:2023-12-01 11:40:45 25 4
gpt4 key购买 nike

我想在按下提交按钮后出现新窗口时隐藏上一个窗口框架,如何隐藏上一个窗口或在不按十字按钮的情况下关闭它

enter code here
public static void main(String[] args)
{

JFrame frame = new JFrame("Project Format Creator");

JButton btn5 = new JButton("submit");
JPanel panel = new JPanel(new GridBagLayout());
GridBagConstraints cst = new GridBagConstraints();

cst.fill = GridBagConstraints.HORIZONTAL;
cst.gridx = 0;
cst.gridwidth = 1;
cst.weightx = 0.1;
cst.gridy = 8; //third row
panel.add(btn5,cst);

btn5.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
JFrame frame1 = new JFrame("Project Format Creator");
frame1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame1.setSize(300,300);//int width int height
frame1.getContentPane().add(panel);
frame1.setVisible(true);

}
});



frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(300,300);//int width int height
frame.getContentPane().add(panel);
frame.setVisible(true);
}

最佳答案

如果您要再次显示该 JFrame,请使用 Frame.setVisible(false);;如果您已完成,请使用 Frame.dispose(); .

   public void actionPerformed(ActionEvent e)
{
frame.dispose(); // dispose the old frame
JFrame frame1 = new JFrame("Project Format Creator");
frame1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame1.setSize(300,300);//int width int height
frame1.getContentPane().add(panel);
frame1.setVisible(true);
}

关于java - 我想在新框架窗口出现时隐藏第一帧,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29546102/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com