单击JButton后关闭jFrame [英] Closing jFrame after clicking JButton

查看:143
本文介绍了单击JButton后关闭jFrame的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在NetBeans中设计了两个JFrame。

I have designed two JFrames in NetBeans.

当我点击规则按钮(即放在JFrame1上)时,它会打开第二个JFrame(但是JFrame2会打开)在JFrame1的窗口,这是我不想要的)。
在第二个JFrame中有一个关闭按钮。但是当我点击这个按钮时,我想要打开JFrame1并且它也正常工作,但JFrame2实际上没有关闭,而JFrame1正在JFrame2上出现。

When I click the "rules" button (i.e placed on JFrame1) then it opens a second JFrame (but JFrame2 opens over JFrame1's window, that's what I dont want). In the second JFrame there is a "close" button. But when I click this button, I want JFrame1 to be opened and it is working too, but JFrame2 is actually not closed and JFrame1 is appearing over JFrame2.

简而言之主要形式是JFrame1。当我点击JFrame1中的规则按钮时,它会在JFrame1上打开JFrame2,而在JFrame2中,当点击主窗体(即JFrame1)时,会有一个关闭按钮,但它会在JFrame2上启动。

In short the main form is JFrame1. When I click the "rules" button from JFrame1 it opens JFrame2 over JFrame1, and in JFrame2 there is a "close" button when it gets clicked the main form (i.e JFrame1) is lauched but it is launched over JFrame2.

场景是JFframe1 - > JFrame2 - > JFrame1

The scenerio is JFframe1 -> JFrame2 -> JFrame1

现在我的问题是点击规则按钮后,JFrame1应该关闭,JFrame2显示在屏幕上,反之亦然。

Now my question is after clicking the "rules" button, JFrame1 should be closed and JFrame2 displayed on the screen and vice versa.

推荐答案

假设你的按钮有一个actionListener,点击规则按钮后放入:

Assuming your button has an actionListener, after clicking the "rules button" put in:

      JFrame1.dispose();  //Remove JFrame 1
      JFrame2.setVisible(true) //Show other frame

然后尊重他们反对的反应

And then reverese them for the opposite reaction

这篇关于单击JButton后关闭jFrame的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆