Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

to change the button picture present in the resources folder in netbeans on click

 
sanjay ramaswamy
Greenhorn
Posts: 29
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 .
 
Rob Spoor
Sheriff
Pie
Posts: 20388
46
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why not use a simple boolean flag that indicates the state?
 
sanjay ramaswamy
Greenhorn
Posts: 29
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Rob Spoor
Sheriff
Pie
Posts: 20388
46
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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:
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic