单击按钮后,打开一个新的JFrame并关闭上一个 [英] Opening a new JFrame and close previous after clicking button
本文介绍了单击按钮后,打开一个新的JFrame并关闭上一个的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我该如何编码一个按钮,当单击该按钮时,该按钮会关闭当前的JFrame
并打开一个新的按钮?
How can I code a button that, when clicked, closes the current JFrame
and opens a new one?
这是我到目前为止的内容,但旧框架保持打开状态:
This is what I have so far, but the old frame stays open:
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
practise1 s = new practise1();
s.setVisible(true);
}
我尝试在第一个{
之后使用.close()
,但这给我一个错误.
I have tried using .close()
after the first {
but it gives me an error.
推荐答案
如果以后打算使用原始JFrame,请在原始JFrame上使用setVisible(false)
.如果计划关闭第一个JFrame且从不重复使用,则可以使用dispose()
.
If you plan on using the originial JFrame later, use setVisible(false)
on the original JFrame. If you plan on closing the first JFrame and never reusing it, you can use dispose()
.
这篇关于单击按钮后,打开一个新的JFrame并关闭上一个的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文