Change photo when you click a button

家住魔仙堡 提交于 2019-12-02 08:29:30
Hovercraft Full Of Eels

You never call pic.setIcon(...) on the JLabel within your ActionListener. You only call it once within the Stage1 constructor, and so the JLabel's Icon will never change. The solution is to call this method within the listener.

Your problem is one of "magical thinking", thinking that if you change the object that a variable refers to, all other references to the object will change as well, but that's not how Java works. When you change the Icon that ic refers to, this has no effect on the current object displayed in the JLabel. You have to write code to change it yourself.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!