• Post Reply Bookmark Topic Watch Topic
  • New Topic

setBackground(java.awt.color) isn't working  RSS feed

 
john price
Ranch Hand
Posts: 495
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

What the heck is wrong with this code?

Here is the error:

Thanks,
John Price aka cc11rocks
 
Mohamed Sanaulla
Bartender
Posts: 3174
34
Google App Engine Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is the type for this here?
 
john price
Ranch Hand
Posts: 495
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


I also tried:

Where frame = JFrame.
No errors for the second one, but it's not working either.
 
john price
Ranch Hand
Posts: 495
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Taking out the keyword "this" fixed the problem.
Thanks for your help,
cc11rocks aka John Price
 
Matthew Brown
Bartender
Posts: 4568
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The reason is that 'this' referred to the ActionListener. If you're in an inner class like that, and need to refer to the containing object, you can use 'ContainingClass.this'.

Though, as you discovered, in this case you didn't need to as setBackground was unambiguous.
 
john price
Ranch Hand
Posts: 495
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Another way I figured out i to put the code in a method. Then, you can use the keyword "this" and just call the method. I did this because I was reusing it several times.
Thanks,
cc11rocks
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!