java icon动态变换,以编程方式自动更改ImageIcon [Java]
I am making a simple game right now. When a JButton is clicked, the ImageIcon of a JLabel is supposed to change. How can I accomplish this?
解決方案
Simple, just quickly run setIcon() on the JLabel via the action listener of the button.
An example:
if ("burp".equals(evt.getActionCommand())) {
charLabel.setIcon(burpIcon);
Sounds.burp();
}
As mentioned by MadProgrammer, any issue you have seeing real-time changes to setIcon() will probably warrant a look at how you've actually designed the class, rather than attempting a hacky workaround to force the ImageIcon to function as it should with the proper setup.
總結
以上是生活随笔為你收集整理的java icon动态变换,以编程方式自动更改ImageIcon [Java]的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: python怎么播放mp3_python
- 下一篇: 零基础自学java_零基础学Java——