繁体   English   中英

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

[英]When i close my fram from addMouseListener it say that this is incompatible type so with what can i change this?

我的代码dispatchEvent(new WindowEvent(this, WindowEvent.WINDOW_CLOSING))不起作用:

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));

                }

            }
        }
    });

由于您使用的是内部类, this指向内部实例。 要获取外部实例,请使用:

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

“ this”是指MouseListener,而不是框架。

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM