[英]How do I close a JDialog and have the Window Event Listeners be notified?
[英]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像我希望的那樣工作:
任何建議都非常歡迎!
如果我需要提供更多代碼或信息,請問我,我會相應地提供。
編輯: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
方法,該方法在frame類中。 擺脫main
方法,添加窗口偵聽器並將其在構造函數中設置為可見。
我不知道您為什么要嘗試在對話框類的main方法中實例化對話框。 它只需要從框架類實例化。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.