Java:设计除主框架之外的 JFrame

发布于 2025-01-05 18:57:23 字数 340 浏览 3 评论 0原文

我已经使用 netbeans GUI 生成器创建了一个 JFrame 表单,并在其上放置了按钮,一切都运行良好。现在我想要的是在按下按钮时调用另一个 JFrame。我还编写了一段代码及其工作原理,但问题是我想设计这个 JFrame 的方式与我设计主 JFrame 的方式相同,因为 GUI 构建器仅向我显示第一个 JFrame。请指导我在这个场景中做什么。

JFrame v = new JFrame("Password");

v.setVisible(true);

v.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

v.setSize(100, 100);

I have created a JFrame form using netbeans GUI builder and place buttons on it and everything is functioning well.Now what i want is to call another JFrame when i press a button.This i have also written a code and its working but the problem is that i want to design this JFrame the same way i designed it my main JFrame where as the GUI builder shows me the first JFrame only.Please guide me what to do in this scenerio.

JFrame v = new JFrame("Password");

v.setVisible(true);

v.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

v.setSize(100, 100);

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

九厘米的零° 2025-01-12 18:57:23

我假设你使用的是netbeans,如果我错了(你没有说),我很抱歉。

有两种方法可以做到这一点,第一种是为新的 JFrame 创建一个单独的表单(右键单击>新建>JFrame),然后在单击按钮时创建它的新实例。

第二个选项是将其添加到 GUI 构建器中,如果执行此操作,它一开始不会显示,您必须转到左侧的组件列表,然后单击“其他组件”>jframe1 以使其显示(这将隐藏您的主表单,您可以通过单击导航器中的主表单组件来隐藏该主表单。

I will assume your using netbeans so sorry if I'm wrong about that (you didn't say).

There are two way to do this the first is to create a separate form for your new JFrame (Right-click>New>JFrame) and then create a new instance of it when your button is clicked.

The second option is to add it in GUI builder if you do this it won't show at first, you have to go to the left hand side where there is a list of components and click on Other Components>jframe1 to make it appear (this will hide your main form which you can hide by clicking on the main form component in the navigator.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文