to change the button picture present in the resources folder in netbeans on click
Joined: Feb 11, 2009
Hey guys i have worked on 1 or 2 small assignments in swings . I am currently trying to develop a Burglar Alarm System . so i need to use buttons to start the system and shut it . so i have 2 .png image files in my resources folder in my netbeans project . so the button is default with the OFF.png file in it . so i want to perform an Action on the button . code goes like this
what am i trying to do ???
I am trying to change the icon of the button to ON on a button click and execute whatever the code when the system is supposed to be ON .vice versa for OFF .
please help me compare the resource files on the button .
"People who are unable to motivate themselves must be content with mediocrity , no matter how impressive their other talents " -Andrew Carnegie
I am not able to get the state of the button . what is a state of the button??? I used the isSelected() method on button i.e
I am kinda starting to wonder...that i can get around by using 2 buttons i.e one for start and one for stop . I am developing a Home Security System. So i need to either manually start the system . so if press the start button it should display the stop icon on the button and execute the code seperately for stop etc .Hope ppl will come up with a code atleast guys...please
Sanjay Jayaram Rao wrote:I am not able to get the state of the button . what is a state of the button??? I used the isSelected() method on button i.e
The isSelected method doesn't make much sense for normal JButtons. It's main use is in JToggleButton, JCheckButton and JRadioButton.
I am kinda starting to wonder...that i can get around by using 2 buttons i.e one for start and one for stop .
That could be an option. You simply hide (setVisible(false)) the one you don't want shown. However, seeing as the layout manager may give you problems, you can achieve the same with two Action instances instead:
The switching code is quite easy then: