通过鼠标侦听器更改Jbutton的图标 [英] Changing Jbutton's Icon Through mouse listener

查看:133
本文介绍了通过鼠标侦听器更改Jbutton的图标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在做一个棋盘游戏项目,我用Jbuttons代表单元.我对所有按钮都做了mouseLitener.我的问题是如何在单击Jbutton时更改其图标?

I'm doing a board game project and I'm representing cells by Jbuttons. I made mouseLitener to all the buttons. My question is how to change the icon of the Jbutton when it is clicked ?

推荐答案

我正在做一个棋盘游戏项目,我用Jbuttons代表单元.

I'm doing a board game project and I'm representing cells by Jbuttons.

  • 使用 JToggleButton 进行基于按钮的游戏数组和鼠标事件,而不是JButton

    • use JToggleButton for game based on buttons array and mouse events, rather than JButton

      使用 ButtonModel 代替任何 XxxListener

      JButtonJToggleButton直接在API中实现了这些方法

      JButton and JToggleButton has implemented these methods in the API directly

      .

      setIcon(Icon i);
      setRolloverIcon(Icon i);
      setPressedIcon(Icon i);
      setDisabledIcon(Icon i);
      

      这篇关于通过鼠标侦听器更改Jbutton的图标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆