[英]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像我希望的那样工作:
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给出以下错误:
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.