有3个Frame,Frame上面没有任何组件,
A窗口是当前窗口时,如果按‘esc’,就退出整个JAVA VM
B窗口是当前窗口时,如果按‘esc’,就退出B,而不退出整个JAVA  VM
C窗口是当前窗口时,如果按‘esc’,就退出C,而不退出整个JAVA  VM这应该如何实现?加载顺序必须是先A,再B,再C,我用过KeyEventPostProcessor这个接口,即使是B窗口为当前激活窗口,一按‘ESC’就全部退出了;如果用dispose(),那么A窗口为当前窗口时也就单独退出,无法实现全部退出
有什么好的解决方案吗?

解决方案 »

  1.   

    设A为主,B中windowClosing(){b.setVisible(false);};,C中windowClosing(){c.setVisible(false);};,这样可以么?
      

  2.   

    那你应该用Dialog啊
    按照你的描述应该是一个模式话对话框啊
      

  3.   

    windowClosing()??是用addWindowsListener吗?不行啊,我试过了
    说白了,是要监听键盘动作,否则实现不了的,但我不知道键盘监听有多少种方法,怎么用
      

  4.   

    每个窗口添加windowlistener,或者windowAdapter,监听窗口事件。
    void windowActivated(WindowEvent e) 
              Invoked when the Window is set to be the active Window. 
     void windowClosed(WindowEvent e) 
              Invoked when a window has been closed as the result of calling dispose on the window. 
     void windowClosing(WindowEvent e) 
              Invoked when the user attempts to close the window from the window's system menu. 
     void windowDeactivated(WindowEvent e) 
              Invoked when a Window is no longer the active Window. 
     void windowDeiconified(WindowEvent e) 
              Invoked when a window is changed from a minimized to a normal state. 
     void windowIconified(WindowEvent e) 
              Invoked when a window is changed from a normal to a minimized state. 
     void windowOpened(WindowEvent e)  
              Invoked the first time a window is made visible覆盖你要的方法就行了,windowClosing或windowClosed都可以
      

  5.   

    可是添加了winlistener后,怎么捕捉键盘动作呢?
      

  6.   

    A窗口是当前窗口时
      System.exit(0);
    B窗口是当前窗口时
      B.setVisiable(false);
      B.setEnable(false);
    C窗口是当前窗口时
      C.setVisiable(false);
      C.setEnable(false);