在另一个JFrame的按钮单击上放置一个JFrame [英] Dispose a JFrame on button click from another JFrame

查看:120
本文介绍了在另一个JFrame的按钮单击上放置一个JFrame的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

许多人可能知道,我是一名完全的Java新手。我已经尝试过对此进行研究(通过阅读StackOverflow上的其他文章,谷歌搜索,并问一个不太喜欢Java新手的朋友),但我不知道。答案可能是明确而容易的,但我对此视而不见。我试图从另一个框架中处置 JFrame

As many probably know, I am a complete Java newbie. I have already attempted to research this (by reading other posts on StackOverflow, Googling and asking a friend who is less of a java newbie) but I can't figure it out. The answer is probably clear and easy but I am blind to it. I am attempting to dispose a JFrame from a different frame.

我的应用程序应按以下方式工作:

My application is supposed to work as follows:


  • 框架X有一个按钮,当按下时:产生框架Y

  • 框架Y有一个按钮,按下时:产生框架Z

  • 框架Z上有一个按钮,按下时:在处理框架Y及其本身之前,从框架Y执行方法。

获取Z帧以处置Y帧是我大多数问题所在。
任何帮助将不胜感激。理想情况下,以这样的方式表达帮助,即使是婴儿也可以理解(因为这是我对Java的理解水平)。

Getting frame Z to dispose frame Y is where most of my issues are. Any help is greatly appreciated. Ideally help will be phrased in such a way that even a baby could understand (because that is my level of Java comprehension).

我知道很多人会认为这是重复的此问题其他问题。我认为这不是重复的问题,因为我已经阅读了这两个书,并且不了解如何解决自己的问题。

I know many will think this is a duplicate question of either this question or this other question. I believe it is not a duplicate question because I have read both and have not understood how to resolve my own problem.

推荐答案



  • 按下框架Z时有一个按钮:在放置框架Y及其本身之前,从框架Y执行方法。

框架Y和框架Z应该是模式对话框(至少Z应该是,可能也是Y)。

Frame Y and frame Z should be modal dialogs (at least Z should be, probably also Y).

当对话框Y打开对话框Z(我们将其称为 dialogZ )时,代码应如下所示:

When dialog Y goes to open dialog Z (we'll call it dialogZ) the code should go something like this:

DialogZ dialogZ = new DialogZ(..);
dialogZ.setVisible(true);
this.setVisible(false); // at this point, dialogZ will have been closed

请参见如何在对话框中使用模态以获取详细信息和示例代码。

See How to Use Modality in Dialogs for details and example code.


(框架Z)…执行方法,从框架Y

框架Y和框架Z应该 扩展任何类。相反,它们应该是根据需要使用的实例变量。

Frame Y and Frame Z should probably not extend any class. Instead they should be instance variables that are used as needed.

这篇关于在另一个JFrame的按钮单击上放置一个JFrame的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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