当我从addMouseListener关闭我的fram时,它说这是不兼容的类型,所以我可以改变它?
问题描述:
我的代码dispatchEvent(new WindowEvent(this, WindowEvent.WINDOW_CLOSING))
这么想的工作:当我从addMouseListener关闭我的fram时,它说这是不兼容的类型,所以我可以改变它?
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));
}
}
}
});
答
dispatchEvent(new WindowEvent(this, WindowEvent.WINDOW_CLOSING));
“这” 指的MouseListener,而不是框架。
查找活动窗口,你可以这样做:由于您使用的是内部类this
点内实例
Window window = SwingUtilities.windowForCompoent(e.getComponent());
dispatchEvent(new WindowEvent(window, WindowEvent.WINDOW_CLOSING));
请显示您的错误日志。 – Gary99
什么不起作用?你有错误吗?使用调试器并检查代码是否被调用。 –