zoukankan      html  css  js  c++  java
  • 窗体焦点监听事件WindowFocusListener

     

    public class Demo extends JFrame {
        JLabel label;//定义变量,以便在自定义方法类中调用
    
        public Demo() {
            setBounds(100, 100, 300, 300);
            setResizable(false);
            setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
            Container c = getContentPane();
    //面板,黑色背景,以适应两张图片的黑色背景
            JPanel panel = new JPanel();
            panel.setBackground(Color.BLACK);
            c.add(panel);
    //Label,用来展示图片
            label = new JLabel();
            panel.add(label);
    //调用自定义方法类
            addWindowFocusListener(new MyWindowFocusListener());
    
            setVisible(true);
        }
    
        class MyWindowFocusListener implements WindowFocusListener {
    
            public void windowGainedFocus(WindowEvent e) {
                label.setIcon(new ImageIcon(Demo.class.getResource("light.png")));
            }
    
            public void windowLostFocus(WindowEvent e) {
                label.setIcon(new ImageIcon(Demo.class.getResource("dark.png")));
            }
        }
    
        public static void main(String[] args) {
            new Demo();
        }
    }
  • 相关阅读:
    音频处理入门笔记
    python对象-多态
    python对象的不同参数集合
    python多重继承的钻石问题
    python对象的多重继承
    python类继承的重写和super
    Python继承扩展内置类
    python对象继承
    Python模块与包
    Pyhton对象解释
  • 原文地址:https://www.cnblogs.com/xixixing/p/9486841.html
Copyright © 2011-2022 走看看