Java:处理来自不同 JFrame 的 ActionEvent
我希望一个 JFrame 具有这样的方法:
private void someEvent(java.awt.event.ActionEvent evt){
//initialize another JFrame
//set the new JFrame to be visible
//set this JFrame to be disabled
}
这是可能的,但我也希望主 JFrame 在新创建的 JFrame 被释放时执行某些操作。但是,我不想将主 JFrame 传递给新的 JFrame。这可能吗?
I want one JFrame to have a method like this:
private void someEvent(java.awt.event.ActionEvent evt){
//initialize another JFrame
//set the new JFrame to be visible
//set this JFrame to be disabled
}
Which is possible, but I also want the main JFrame to perform something when the newly created JFrame is disposed. I don't want to pass in the main JFrame to the new JFrame however. Is this possible?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
相反,请使用
CardLayout
< /a> 在两个所需的内容窗格之间切换。 此处有一个示例。Instead, use
CardLayout
to switch between the two desired content panes. There's an example here.不要让一个 JFrame 创建并显示另一个 JFrame。相反,第二个窗口应该是 JDialog,如果您希望第一个窗口冻结直到处理第二个窗口,则可以是模态窗口,否则可以是非模态窗口。如果是模态的,那么一旦 JDialog 被释放,第一个窗口的代码将恢复,并且代码流将在对话框上的
setVisible(true)
调用之后立即开始。如果是非模态的,您可能需要向对话框添加 WindowListener。例如,请在此处查看我的代码,此处,以及此处。
Don't have one JFrame create and display another JFrame. Instead the second window should be a JDialog, either modal if you want the first window frozen until the second has been dealt with or non-modal if otherwise. If modal then the first window's code will resume once the JDialog has been disposed of, and the code flow will start right after the
setVisible(true)
call on the dialog. If non-Modal, you'll likely want to add a WindowListener to the dialog.For example, please check out my code here, here, and here.