swing模拟窗口关闭事件

1、窗口属性 xxx.setDefaultCloseOperation(EXIT_ON_CLOSE);

2、模拟事件 WindowEvent we = new  WindowEvent(xxx.this,WindowEvent.WINDOW_CLOSING);
3、事件分发 xxx.this.dispatchEvent(we);

 

其他事件模拟

 

Toolkit.getEventQueue().postEvent(
                        new ActionEvent(Button.this,
                                        ActionEvent.ACTION_PERFORMED,
                                        Button.this.getActionCommand()));

你可能感兴趣的:(swing)