wood burning stoves 2.0*
The moose likes Swing / AWT / SWT and the fly likes Trying to get a square change color on button click Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Trying to get a square change color on button click" Watch "Trying to get a square change color on button click" New topic
Author

Trying to get a square change color on button click

Timothy Oldbean
Greenhorn

Joined: Jun 23, 2011
Posts: 17
EDIT: Obviously a beginners question! Probably in the wrong forum, please feel free to move mods! Apologies!

I thought I'd help myself understanding the GUI and ActionListener proces a bit better by sussing out how to do something simple like putting a button and a rectangle on a screen and then having it change color from blue to red on buttonclick.

Appears I've ended up in a swamp and everytime I move I get sucked farther in.

I soon found out I have no clue how to easily change the color of something when clicking a button so I thought I'd fake it first by simply running a different color panel on mouseclick. And that failed miserably too! Trying to use the boolean swoosh in two different classes is not the way to go. So a little help, hint or push in the right direction would be greatly appreciated!






If it wasn't for physics and law enforcement, I'd be unstoppable!
Timothy Oldbean
Greenhorn

Joined: Jun 23, 2011
Posts: 17
I'm trying to get the boolean to work in another class through using getter and setter but now I've run into a new problem. I get an error on the getter method.

Timothy Oldbean
Greenhorn

Joined: Jun 23, 2011
Posts: 17
Stuck for hours and as soon as I post here I start getting somewhere.

I think I've got the getter and setter part sorted now:


The challenge I have now is to get the value of boolean swoosh into the if else statement which I'm wrongly attempting to do like so at the moment:

Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
you've a number of things around the wrong way

comments should be self-explanatory

compile/run, the clicking the button numerous times will alternate between the two colors



note: if you had added 'recty' anywhere else but center, it would not have shown up (try adding it to NORTH).
without components, it normally needs to have a preferredSize set
Timothy Oldbean
Greenhorn

Joined: Jun 23, 2011
Posts: 17
Thanks a lot Michael!

I'm going to take my time tomorrow comparing your code to mine and see where I went wrong. By the first look of it I see you doing a couple of things I haven't seen yet and thus don't understood so I might have a couple of extra questions later after I try to find it out myself.

 
 
subject: Trying to get a square change color on button click
 
Similar Threads
GUI Problem
GUI Example (HFJ)
why does this code fail?
I'm not able to compile the below prog...can you pleas tell me what is the error in using while loop
need help with my code