为什么只有 windowGainedFocus() 不起作用?

Why only windowGainedFocus() does not work?

我有以下代码,我在其中向我的 JFrame 添加了一个 WindowListener,我想重写该方法 windowGainedFocus:

    final JFrame jd = new JFrame();
    jd.setLocationRelativeTo(null);
    jd.setSize(300, 425);
    jd.setLayout(null);
    jd.setResizable(false);

    jd.addWindowListener(new WindowAdapter() {
         public void windowGainedFocus(WindowEvent windowEvent){
               System.out.println("TEST");
         }        
    }); 

但它不起作用,当我聚焦此帧时它不打印 "TEST"。 但是当我覆盖方法 windowClosing 时它起作用了:

    jd.addWindowListener(new WindowAdapter() {
         public void windowClosing(WindowEvent windowEvent){
               System.out.println("TEST");
         }        
    }); 

windowGainedFocus()有什么问题?

jd.addWindowListener(new WindowAdapter() {
     public void windowGainedFocus(WindowEvent windowEvent){
           System.out.println("TEST");
     }        
}); 

应该是:

jd.addWindowFocusListener(new WindowAdapter() {
     public void windowGainedFocus(WindowEvent windowEvent){
           System.out.println("TEST");
     }        
}); 

知道我讨厌适配器类是有充分理由的。我建议使用监听器而不是适配器。