简体   繁体   English

net上的主要gui和newjdialog混在一起

[英]main gui and newjdialog mixed up on netbeans

I have created new java application on Netbeans by pressing create new project and it creates java package. 我通过按create new project在Netbeans上创建了新的Java应用程序,它创建了Java包。 This fully fine ! 这样完全可以了! When I add new JFrame it creates and automatically MAIN METHOD , after I am done with Matisse I mean putting some gui components , I want to add JDialog to that , I go on package right click and create JDialog Form which also created MAIN METHOD as well so itself. 当我添加新的JFrame时,它会创建并自动执行MAIN METHOD,在完成Matisse之后,我的意思是放一些gui组件,我想在其中添加JDialog,然后继续右键单击并创建JDialog Form,它也创建了MAIN METHOD本身也是。 So both MAINS mixes up. 因此,两个MAINS混合在一起。 this is confusing me all the time. 这一直困扰着我。 My Aim is to create JMenuItem called new , when I click on it I want my JDialog to be appear and something like project creation dialog. 我的目标是创建一个名为new的JMenuItem,当我单击它时,我希望我的JDialog出现,并且类似项目创建对话框。 Help please ! 请帮助 ! How to combine to different components in these situations ? 在这些情况下如何组合成不同的组件?

Regards 问候

"this so confusing always , do have some examples " “这总是令人困惑,请举一些例子”

I'm not so sure what is so confusing. 我不确定是什么让我感到困惑。 Your program should only have one launching class with a main method. 您的程序应该只有一个带有main方法的启动类。 Netbeans will create a main method for you in JDialog forms, so just delete the main method. Netbeans将以JDialog形式为您创建一个main方法,因此只需删除main方法即可。 The only main method you need is your main JFrame form. 您唯一需要的main方法是JFrame主窗体。

You have your JDialog form 您有JDialog表单

public class MyDialog extends javax.swing.JDialog {
    public MyDialog(final Frame parent, boolean modal) {
        super(parent, model);
        initComponents();
    }

    private void initiComponent() {
        ...
    }

    // delete the auto-generated main method
}

You have your JFrame form with JMenuItem . 您的JFrame表单带有JMenuItem Add a listener to the JmenuItem to open the MyDialog 将侦听器添加到JmenuItem以打开MyDialog

public class MyFrame extends javax.swing.JFrame {
    private javax.swing.JMenuItem jMenuItem1;

    public MyFrame() {
        initComponents();
    }

    /* Auto-generated code */
    private void initComponents() {
        jMenuItem1 = new JMenuItem();
        jMenuItem1.addActionListener(new java.awt.event.ActionListener(){
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem1ActionPerformed(evt);
            }
        });
    }

    /* Auto-generated method */
    private jmenuItemActionPerformed(java.awt.event.ActionEvent evt) {
        /* Your hand written code */
        MyDialog dialog = new MyDialog(MyFrame.this, true);
    }

    public static void main(String[] args) {

    }
}

" How to combine to different components in these situations ? " “在这种情况下如何结合到不同的组成部分?”

What does that even mean ? 那到底是什么意思


Side Note 边注

  • I'd recommend going through Swing Tutotials and learning to hand code before jumping in to GUI Builder tools. 我建议您先使用Swing Tutotials并学习编写代码,然后再跳入GUI Builder工具。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM