How to use setVisible in JFrames?(如何在 JFrames 中使用 setVisible?)
问题描述
在我的程序中,我有两个 JFrame
实例.当我单击 next
按钮时,我想显示下一帧并隐藏当前帧.所以我使用 this.setVisible(false)
和 new Next().setVisible(true)
.但是在 Next
窗口中,如果我单击 back
按钮,我想将前一帧设置为再次可见并且下一帧必须结束(这意味着它必须退出).
In my program I have two JFrame
instances. When I click next
button I want to show next frame and hide current frame. So I use this.setVisible(false)
and new Next().setVisible(true)
. But in Next
window if I click back
button I want to set previous frame to be visible again and next frame must be ended (which means it must be exited).
有什么特殊的方法可以做到这一点吗?我该怎么做?
Is there any special method(s) to do this? How can I do it?
推荐答案
考虑使用 CardLayout 而不是寻找有多少 JFrames 有.那么..
Consider using CardLayout instead of hunting for how many JFrames there are. Then..
- 只需要一个 JFrame
- 任何下一步/后退操作都只会在卡片之间切换
此论坛中有很多示例 - 例如如图所示这里.
There are lots of examples in this forum - e.g. as shown here.
这篇关于如何在 JFrames 中使用 setVisible?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何在 JFrames 中使用 setVisible?


基础教程推荐
- 首次使用 Hadoop,MapReduce Job 不运行 Reduce Phase 2022-01-01
- 如何在不安装整个 WTP 包的情况下将 Tomcat 8 添加到 Eclipse Kepler 2022-01-01
- 在螺旋中写一个字符串 2022-01-01
- Spring Boot Freemarker从2.2.0升级失败 2022-01-01
- 由于对所需库 rt.jar 的限制,对类的访问限制? 2022-01-01
- 如何对 HashSet 进行排序? 2022-01-01
- 如何强制对超级方法进行多态调用? 2022-01-01
- 如何使用 Stream 在集合中拆分奇数和偶数以及两者的总和 2022-01-01
- 如何使用 Eclipse 检查调试符号状态? 2022-01-01
- Java 中保存最后 N 个元素的大小受限队列 2022-01-01