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

丹尼·霍夫(Danny Hoeve)

我在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方法,该方法在框架类中。摆脱该main方法,添加窗口侦听器并将其在构造函​​数中设置为可见。

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

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章