dispose java_无法使用dispose()方法关闭Java中的JFrame

所以这就是问题所在。我正在创建一个使用JFrame的程序。它的基本功能是打开一个窗口,询问您打开哪个窗口。该程序由多个GUI类和多个Client类组成,负责在每个GUI打开时为其创建一个新窗口。因此,当加载MainClient类时,它会创建一个窗口来保存MainGUI类。从那里选择ComboBox中的一个选项,然后单击"继续"应该启动另一个客户端类打开另一个JFrame。这一切都很好,除了我不能为我的生活弄清楚为什么我不能使用.dispose()方法删除旧窗口。我所能做的就是使用setVisible(false)方法清除它,但它仍然在我的新窗口的背景中挂起。每当我尝试在setVisible()方法之后直接使用dispose方法时,我得到这个错误"找不到符号 - 方法dispose()"

如果有人知道为什么会这样,我会对此有所帮助!这是导致错误的我的MainGUI类的代码(错误在底部附近被注释掉并被星号包围):

import java.awt.*;

import javax.swing.*;

import java.awt.event.*;

public class MainGUI extends JPanel

{

protected JLabel topLabel;

protected JButton continueButton;// To continue to the next form

private MainHandler handler = new MainHandler(this); // An instance of the inner event handler

protected final String[] OPTIONS = {"Search/Delete Employee Records","Insert New Employee",

"Insert New Manager","Retrieve Department Metadata"};

protected JComboBox optionsCombo; //Combo box to select options from

protected InsManGUI insGUI;

public MainGUI ()

{

setLayout (new FlowLayout());

topLabel = new JLabel("Please select which action you wish to perform");

topLabel.setHorizontalAlignment(JLabel.CENTER);

continueButton = new JButton("Continue");

continueButton.setHorizontalAlignment(JLabel.CENTER);

optionsCombo = new JComboBox(OPTIONS);

add(topLabel);

add(optionsCombo);

add(continueButton);

continueButton.addActionListener(new MainHandler(this));

optionsCombo.addActionListener(new MainHandler(this));

}

}

// Inner eventhandler class to compute which form to open once the Continue button is clicked.

class MainHandler implements ActionListener

{

//Private varible to hold an instance of the MainGUI class

private MainGUI gui;

public MainHandler(MainGUI gui)

{

//Set the private GUI varible to a particular GUI

this.gui = gui;

EmployeesDB.connect();

}

public void actionPerformed(ActionEvent e)

{

if(e.getSource() == gui.continueButton)

{

if(gui.optionsCombo.getSelectedItem() == "Insert New Manager")

{

gui.setVisible(false);

InsManClient man = new InsManClient();

//gui.dispose();*******************THIS LINE WON't //COMPILE*************************

}

if(gui.optionsCombo.getSelectedItem() == "Insert New Employee")

{

gui.setVisible(false);

InsEmpClient emp = new InsEmpClient();

}

if(gui.optionsCombo.getSelectedItem() == "Search/Delete Employee Records")

{

gui.setVisible(false);

SearchClient ser = new SearchClient();

}

if(gui.optionsCombo.getSelectedItem() == "Retrieve Department Metadata")

{

gui.setVisible(false);

MetaDataClient met = new MetaDataClient();

}

}

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值