桌面应用程序 - 如何动态创建和销毁表单
我正在使用 java 为桌面创建一个小型加密应用程序。
我正在将 JFrames(导入 javax.swing.JFrame)与 Oracle 一起使用 Linux 下的 JDeveloper 11g。
我想要一个“欢迎”表单/框架供用户选择 他们的加密方法,然后选择方法, 我想动态地创建适当的表单 选择加密方法并销毁/释放/处置() 欢迎表格。当用户完成加密后, 他们应该关闭框架/表单(通过单击 x 在右上角 - 或使用“退出”按钮或通过任何 方法)并且欢迎框架应该动态重新创建 并出现。
我尝试过各种方法 - btnEncode_actionPerformed(ActionEvent e) 然后 this.dispose() - 我摆弄了 this_windowClosed(WindowEvent e) 和 dispose(),但似乎没有任何作用。
即使使用 setVisibl(true/false) 的解决方法也是可以接受的 这个阶段——这让我一整天都伤透了脑筋。这是非常 在德尔福很容易做到!
TIA 和 rgs,
保罗...
I'm creating a small crypto app for the desktop using java.
I'm using JFrames (import javax.swing.JFrame) with Oracle
JDeveloper 11g under Linux.
I want to have a "welcome" form/frame where users can choose
their encryption method, and then on choosing the method,
I want to dynamically create the appropriate form for the
chosen encryption method and also destroy/free/dispose() of
the welcome form. When the user has finished their encrypting,
they should close the frame/form (either by clicking on the
x at the top right - or using the Exit button or by any
method) and the welcome frame should be dynamically recreated
and appear.
I've tried various things - btnEncode_actionPerformed(ActionEvent e)
then this.dispose() - and I've fiddled with this_windowClosed(WindowEvent e)
and dispose(), but nothing seems to work.
Even a workaround using setVisibl(true/false) would be acceptable at
this stage - this has been wrecking my head all day. It's very
easy to do in Delphi!
TIA and rgs,
Paul...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
像这样的东西通常可以解决问题:(注意我还没有测试过这个)
其中 btnContinue 是欢迎表单上的“继续”按钮,而 JFrameAppropriateWindow 是您想要根据用户的选择显示的下一帧。 Args 是您需要传递的任何参数。
准备好后,您可以简单地处理当前框架并重新启动 WelcomeMsg 的实例
something like this usually does the trick: (Note I haven't tested this)
where btnContinue is the Continue button on your welcome form and JFrameAppropriateWindow is the next frame you would like to show depending on the user's choice. Args are any arguments you need to pass.
When you are ready, you can simply dispose the current frame and relaunch an instance of WelcomeMsg
我整理了这个简单的示例,用于根据用户的选择创建和显示面板。
当我想到这一点时,您可能应该使用 CardLayout,它允许您在不同的面板(卡片)之间切换。
I put together this simple example for creating and displaying a panel depending on a user choice.
When I come to think about it, you should probably use a CardLayout instead, which allows you to switch between different panels (cards).