我在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像我希望的那样工作:
任何建议都非常欢迎!
如果我需要提供更多代码或信息,请问我,我会相应地提供。
编辑:masterTable.addMouseListener在公共void initComponents()内部。新JDialoog(InzienGegevensSelectie)中的this给出以下错误:
新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] 删除。
我来说两句