java 使用 netbeans 上的 GUI 构建器在主 GUI 上打开新的 GUI 窗口
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13902907/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Opening a new GUI window on a main GUI using GUI builder on netbeans
提问by Marcello
I am playing about with GUI builder and i was wondering if there is an easy way to open the register window through the current main window (in reference to the page below). I am trying to do this through the menu bar.
我正在玩 GUI builder,我想知道是否有一种简单的方法可以通过当前主窗口打开注册窗口(参考下面的页面)。我正在尝试通过菜单栏执行此操作。
I've been trying all day, because GUI Builder generates some code, its not possible to edit this code.
我一整天都在尝试,因为 GUI Builder 生成了一些代码,无法编辑此代码。
Thanks For the help!
谢谢您的帮助!
回答by Branislav Lazic
Create a separate class which extends JDialog
class and add your GUI components:
创建一个单独的类来扩展JDialog
类并添加您的 GUI 组件:
public Register extends JDialog {
//Make GUI
setModalityType(ModalityType.APPLICATION_MODAL); //Make it modal
}
Add ActionListener
to that menu item which is supposed to open a register window:
添加ActionListener
到应该打开注册窗口的菜单项:
mnuItmRegisteration.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
Register r = new Register();
r.setVisible(true);
}
});
回答by junyi00
Right click on that shortcut button, click Events, click ActionPreformed.
There you should write codes to make your register window appear.
An example:
右键单击该快捷按钮,单击事件,单击 ActionPreformed。
在那里你应该编写代码来让你的注册窗口出现。
一个例子:
private void RegisterationEventActionPerformed(java.awt.event.ActionEvent evt) {
JFrame Register = new Register();
Register.setVisible(true);
}
Remember to make another JFrame called ("Register" assuming u are using the code i gave) at the same package as your current JFrame Maybe u would probably should use the run button (The button with a Green Triangle or Arrow), run it try to press the menu item, it should appear the register window.
请记住在与当前 JFrame 相同的包中创建另一个名为(“注册”,假设您正在使用我提供的代码)的 JFrame 也许您应该使用运行按钮(带有绿色三角形或箭头的按钮),运行它试试按菜单项,它应该出现注册窗口。