• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 .
 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why not use a simple boolean flag that indicates the state?
 
sanjay ramaswamy
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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:
 
reply
    Bookmark Topic Watch Topic
  • New Topic