当我从addMouseListener关闭我的fram时,它说这是不兼容的类型,所以我能改变这个吗?

时间:2017-03-16 15:22:38

标签: java

我的代码jTable1.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { if (e.getClickCount() == 2) { int select = jTable1.getSelectedRow(); int choi = JOptionPane.showConfirmDialog(null, "Voulez Vous vraiment choisir ce client ?"); if(choi == 0){ Utile.idClient=jTable1.getModel().getValueAt(select, 0).toString(); dispatchEvent(new WindowEvent(this, WindowEvent.WINDOW_CLOSING)); } } } }); 没有工作:

MyTable

2 个答案:

答案 0 :(得分:1)

因为您使用内部类this指向内部实例。要使用外部实例:

MyFrame.this 

答案 1 :(得分:0)

dispatchEvent(new WindowEvent(this, WindowEvent.WINDOW_CLOSING));

"这"指的是MouseListener,而不是框架。

要查找活动窗口,您可以执行以下操作:

Window window = SwingUtilities.windowForCompoent( e.getComponent() );
dispatchEvent(new WindowEvent(window, WindowEvent.WINDOW_CLOSING));