baiyajin
ABCHERRY7
采纳率0%
2017-10-24 08:41 阅读 2.3k

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条回答 默认 最新

相关推荐