简体   繁体   English

为了显示它,我必须给JDialog什么样的变量

[英]What kind of variable do I have to give to a JDialog in order to show it

I'm using Design mode on NetBeans in order to create multiple JFrames. 我在NetBeans上使用“设计”模式以创建多个JFrame。 I'm currently trying to make a JDialog but I don't know what kind of variable I have to give it. 我目前正在尝试制作JDialog,但是我不知道该给它什么样的变量。

Because Design-mode made the code for me, I can't just edit it in order to let it work. 因为设计模式为我编写了代码,所以我不能仅仅为了使其工作而对其进行编辑。 It was already quite the hassle to get a doubleClick event in the generated code of the masterTable. 在masterTable的生成代码中获得doubleClick事件已经很麻烦。

this is the code I'm trying to run. 这是我要运行的代码。 The public void DoubleClick is where an new instance for the Jdialog is made. 公开的DoubleClick是为Jdialog创建新实例的地方。

masterTable.addMouseListener( new ClickListener() {
        public void singleClick (MouseEvent e) {
            System.out.println("single");
            JTable target = (JTable) e.getSource();
            int row = target.getSelectedRow();
            int col = 0;
            Object data = (Object) target.getValueAt(row, col);
            String id = data.toString();
            System.out.println("Er is geklikt op de rij met ID nummer: " + data);
            try {
                GetSelectedData(id);
            } catch (SQLException ex) {
                Logger.getLogger(InzienDienstgegevensForm.class.getName()).log(Level.SEVERE, null, ex);
            }
            try {
                DisplayPaymentInfo(id);
            } catch (SQLException ex) {
                Logger.getLogger(InzienDienstgegevensForm.class.getName()).log(Level.SEVERE, null, ex);
            }

        }
        public void doubleClick (MouseEvent e){
            System.out.println("double");
            JTable target = (JTable) e.getSource();
            int row = target.getSelectedRow();
            int col = 0;
            Object data = (Object) target.getValueAt(row, col);
            String id = data.toString();
            System.out.println("Er is geklikt op de rij met ID nummer: " + data);
            InzienSelectieDialoog dialoog = new InzienSelectieDialoog(this, true);
        }
    }); 

My JDIALOG has the following constructor and runnable in public void Run(): 我的JDIALOG具有以下构造函数,并且可以在公共void Run()中运行:

public InzienSelectieDialoog(java.awt.Frame parent, boolean modal) {
    super(parent, modal);
    initComponents();
}

public static void main(String args[]) {

    /* Create and display the dialog */
    java.awt.EventQueue.invokeLater(new Runnable() {
        public void run() {
            InzienSelectieDialoog dialog = new InzienSelectieDialoog(new     javax.swing.JFrame(), true);
            dialog.addWindowListener(new java.awt.event.WindowAdapter() {
                @Override
                public void windowClosing(java.awt.event.WindowEvent e) {
                    System.exit(0);
                }
            });
            dialog.setVisible(true);
        }
    });
}

There are two things I want to adjust in order for me to get this JDialog working like I want it to: 我需要调整两件事,以使此JDialog像我希望的那样工作:

  • I want to make it visible with the right attributes. 我想通过正确的属性使其可见。 So I need to put something at the (...,...) constructor... but I have no clue what I have to put there. 因此,我需要在(...,...)构造函数中放置一些内容...但是我不知道该放在哪里。
  • I want to give a String id (which contains the ID what the Jdialog needs to print the right values) 我想提供一个字符串ID(其中包含Jdialog打印正确值所需的ID)

Any suggestion are very welcome! 任何建议都非常欢迎!

If I need to provide more code or information what I want to do, please ask me and I'll do so accordingly. 如果我需要提供更多代码或信息,请问我,我会相应地提供。

EDIT: the masterTable.addMouseListener is inside the public void initComponents(). 编辑:masterTable.addMouseListener在公共void initComponents()内部。 The this in the new JDialoog (InzienGegevensSelectie) gives the following error: 新JDialoog(InzienGegevensSelectie)中的this给出以下错误:

  • incompatible types < anonymous ClickListener > cannot be converted to Frame 不兼容的类型<匿名ClickListener>无法转换为Frame

The this in the new JDialoog (InzienGegevensSelectie) gives the following error: 新JDialoog(InzienGegevensSelectie)中的this给出以下错误:

incompatible types < anonymous ClickListener > cannot be converted to Frame

new InzienSelectieDialoog(this, true);

You have created the dialog in the context of the ClickListener . 您已经在ClickListener的上下文中创建了对话框。 Meaning this refers to the ClickListener . 这意味着this是指ClickListener To change the this to the frame, you need to prefix the frame's class name like MyFrame.this 要改变this到框架上,你需要的前缀框架的类名像MyFrame.this


Side Note 边注

  • I notice your dialog class has a main method. 我注意到您的对话框类有一个main方法。 You don't need that. 不用了 Your application should only have one main method, which is in the frame class. 您的应用程序应该只有一个main方法,该方法在frame类中。 Get rid of the main method, add the window listener and set it visible in the constructor. 摆脱main方法,添加窗口侦听器并将其在构造函​​数中设置为可见。

  • I don't know why you are trying to instantiate the dialog in the main method of the dialog class. 我不知道您为什么要尝试在对话框类的main方法中实例化对话框。 It should only need to be instantiate in from the frame class. 它只需要从框架类实例化。

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

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