java Swing自定义按钮,最大化到最小化,回来图标就不见了?

java Swing自定义按钮,最大化到最小化,回来图标就不见了?
程序运行,单独点击最大化,最小化没有任何问题,但是如果先点了最大化,再点最小化
再从任务栏点回来,图标就不见了。
//最小化功能
public void minFunction(JLabel min){
min.addMouseListener(new MouseAdapter() {
@Override
public void mouseEntered(MouseEvent e) {
// TODO Auto-generated method stub
min.setIcon(new ImageIcon(hover_min));
}
@Override
public void mouseExited(MouseEvent e) {
// TODO Auto-generated method stub
min.setIcon(new ImageIcon(default_min));
}
@Override
public void mouseClicked(MouseEvent e) {

            realizeMin();

        }
    });
}
//最大化功能
public void maxFunction(JLabel max){
    max.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseEntered(MouseEvent e) {
            // TODO Auto-generated method stub
            max.setIcon(new ImageIcon(hover_max));
        }
        @Override
        public void mouseExited(MouseEvent e) {
            // TODO Auto-generated method stub
            max.setIcon(new ImageIcon(default_max));
        }
        @Override
        public void mouseClicked(MouseEvent e) {
            realizeMax();
            maxFace();
            if(getjFrameState() == 1){
                realizeMax();
                maxFace();
            }else if(getjFrameState() == 2){
                realizeNormal();//点击按钮实现最大化
                normalFace();
            }
        }
    });
}   
//获取窗口状态
int jFrameState;
public int getjFrameState(){
            jFrame.addWindowStateListener(new WindowStateListener() {
            @Override
            public void windowStateChanged(WindowEvent state) {
                // TODO Auto-generated method stub
                if(state.getNewState() == JFrame.NORMAL) {
                    jFrameState = 1;//新窗口正常化
                }else if(state.getNewState() == JFrame.MAXIMIZED_BOTH) {
                    jFrameState = 2;//新窗口最大化
                }else if(state.getNewState() == JFrame.ICONIFIED) {
                    jFrameState = 3;//新窗口最小化
                }else if(state.getOldState() == JFrame.MAXIMIZED_BOTH) {
                    jFrameState = 4;//旧窗口最大化
                }else if(state.getOldState() == JFrame.ICONIFIED) {
                    jFrameState = 5;//旧窗口最小化
                }else if(state.getOldState() == JFrame.NORMAL){
                    jFrameState = 6;//旧窗口正常化
                }
            }
        });
        return jFrameState;
    }

1个回答

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!