• 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
  • Tim Cooke
  • paul wheaton
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Trying to get a square change color on button click

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!





 
Timothy Oldbean
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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:

 
Ranch Hand
Posts: 4632
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.

 
It's never done THAT before. Explain it to me tiny ad:
Clean our rivers and oceans from home
https://www.kickstarter.com/projects/paulwheaton/willow-feeders
reply
    Bookmark Topic Watch Topic
  • New Topic