• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

changing a jframe background color  RSS feed

 
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello All,

I'm pretty new to java and could use some help.  I have a program that is running fine, but the last thing I need to do is have the background of the Jframe change every time a button is clicked.  So I've added a color command to my button and the background changes to green, no problem.  But I don't know how to finish the code by overriding that color if the button is clicked.  Here is the pertinent code:

     

Any suggestions or pointers would be greatly appreciated.  

Thanks                      
 
Master Rancher
Posts: 3004
105
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One simple way would be to have a method getColor(), something like

and in your ActionListener, in stead of using Color.GREEN, use getColor().

edit: read for 'ActionListener'  'MouseListener'
 
Alex Houser
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Piet,

Thanks for the response!  When I added in your code, for lines 4, 5, & 6, I get an "illegal start of expression" error.  Thoughts?
 
Piet Souris
Master Rancher
Posts: 3004
105
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yeah, these dots were meant to be replaced by correct syntax. I did not supply completely working code, because I was afraid I had given already too much information.
Look at how I defined the variable 'red'. You should do something equal to the variables green and blue.
Then have a look at the API of the Color class, to see how you can create a new Color (API).

Tyy it, and let us know whether you succeeded!
 
Alex Houser
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I appreciate that,  I'll give it a try and let you know!
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!