可以从第二页或儿童页面处置
我无法从第二页或子页面处置。编译器报告:找不到符号
如何处理它?
菜单
public class Menu extends javax.swing.JFrame {
/**
* Creates new form Menu
*/
public Menu() {
initComponents();
}
private void jButton1MouseClicked(java.awt.event.MouseEvent evt) {
// TODO add your handling code here:
JFrame app = new JFrame();
Task t = new Task();
t.setVisible(true);
app.add(t);
app.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
app.setSize(690, 340);
app.setVisible(true);
dispose();
}
}
<代码>任务
public class Task extends javax.swing.JPanel {
/**
* Creates new form NewJPanel
*/
public Task() {
initComponents();
}
private void BackButtonMouseClicked(java.awt.event.MouseEvent evt) {
Menu t = new Menu();
t.setVisible(true);
setVisible(false);
dispose(); <-- here
}
}
我从菜单
任务
链接。它已经完成,但是当我回到菜单
时,它无法处理。
I can't dispose from second page or child page. The compiler reports: can not find symbol
How can I dispose of it?
Menu
public class Menu extends javax.swing.JFrame {
/**
* Creates new form Menu
*/
public Menu() {
initComponents();
}
private void jButton1MouseClicked(java.awt.event.MouseEvent evt) {
// TODO add your handling code here:
JFrame app = new JFrame();
Task t = new Task();
t.setVisible(true);
app.add(t);
app.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
app.setSize(690, 340);
app.setVisible(true);
dispose();
}
}
Task
public class Task extends javax.swing.JPanel {
/**
* Creates new form NewJPanel
*/
public Task() {
initComponents();
}
private void BackButtonMouseClicked(java.awt.event.MouseEvent evt) {
Menu t = new Menu();
t.setVisible(true);
setVisible(false);
dispose(); <-- here
}
}
I linked from Menu
to Task
. It's done but when I go back to Menu
it can not be disposed of.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先,不要使用Mouselistener来处理单击按钮。相反,您应该使用旨在用于此目的的ActionListener。
然后,在您的
ActionListener
代码中,您需要在处理框架之前获取包含按钮的帧的引用。您可以从ActionEvent
中获取按钮。基本逻辑是:
First of all, don't use a MouseListener to handle a click on a button. Instead you should be using an ActionListener which was designed to be used for this purpose.
Then in your
ActionListener
code you need to get a reference to the frame containing the button before you can dispose of the frame. You can get the button from theActionEvent
.The basic logic would be: