繁体   English   中英

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

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

我在NetBeans上使用“设计”模式以创建多个JFrame。 我目前正在尝试制作JDialog,但是我不知道该给它什么样的变量。

因为设计模式为我编写了代码,所以我不能仅仅为了使其工作而对其进行编辑。 在masterTable的生成代码中获得doubleClick事件已经很麻烦。

这是我要运行的代码。 公开的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);
        }
    }); 

我的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);
        }
    });
}

我需要调整两件事,以使此JDialog像我希望的那样工作:

  • 我想通过正确的属性使其可见。 因此,我需要在(...,...)构造函数中放置一些内容...但是我不知道该放在哪里。
  • 我想提供一个字符串ID(其中包含Jdialog打印正确值所需的ID)

任何建议都非常欢迎!

如果我需要提供更多代码或信息,请问我,我会相应地提供。

编辑:masterTable.addMouseListener在公共void initComponents()内部。 新JDialoog(InzienGegevensSelectie)中的this给出以下错误:

  • 不兼容的类型<匿名ClickListener>无法转换为Frame

新JDialoog(InzienGegevensSelectie)中的this给出以下错误:

incompatible types < anonymous ClickListener > cannot be converted to Frame

new InzienSelectieDialoog(this, true);

您已经在ClickListener的上下文中创建了对话框。 这意味着this是指ClickListener 要改变this到框架上,你需要的前缀框架的类名像MyFrame.this


边注

  • 我注意到您的对话框类有一个main方法。 不用了 您的应用程序应该只有一个main方法,该方法在frame类中。 摆脱main方法,添加窗口侦听器并将其在构造函​​数中设置为可见。

  • 我不知道您为什么要尝试在对话框类的main方法中实例化对话框。 它只需要从框架类实例化。

暂无
暂无

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

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