在打开新的Java Swing前先关闭旧对话框

时间:2019-10-16 08:12:33

标签: java swing notepad

任何人都可以帮助我,我通过java-swing创建了一个记事本。但是我有一个问题。每当我使用动作事件(替换,查找)并且程序在屏幕上显示它时,并且我再次使用动作事件在屏幕上显示另一个事件,但不会关闭旧的事件。

private void replaceController(MainForm mainForm) {
    mainForm.getReplace().addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            ReplaceForm replaceForm = new ReplaceForm(mainForm, false);
            replaceForm.setVisible(true);
            replaceForm.getBtnReplace().setEnabled(false);
            replaceForm.getBtnReplaceAll().setEnabled(false);



            ReplaceController replaceController = new ReplaceController();
            replaceController.checkEmptyReplace(replaceForm);
            replaceController.replace(mainForm, replaceForm);
            replaceController.f(mainForm, replaceForm);
            replaceController.replaceAll(mainForm, replaceForm);
            replaceController.cancelReplace(replaceForm);
        }
    });

}

1 个答案:

答案 0 :(得分:0)

请注意default close operation会应用于顶级JFrame或JDialog。

如果您只想隐藏框架而不弃置框架,请使用while True: #bunch of stuff happening if #something happens: exec(open("filename.py").read()) #here I tried to call for another script but the while loop won't continue. It just runs this script and finishes, but I need this secont script to run parallel with the while loop looping. 。希望再次将其显示在屏幕上时,将其设置为HIDE_ON_CLOSE。这意味着您只需要框架实例。

如果您希望将其处理掉(看起来像那样,每次调用该操作时都在这里构造一个新对象),请使用visible。然后,每次用户关闭框架都会被破坏。

相关问题