• Post Reply Bookmark Topic Watch Topic
  • New Topic

Make my own Color  RSS feed

 
David A King
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am stuck, and it's probably for a stupid reason. I was trying to make my own Color to use with awt. I useed the statement public static final Color purple = new Color(255,0,255);
When I try to use Color.purple it says it cannot reference purple.

Can somebody tell me what I am not understanding about this?

Thanks,

*Dave
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
David A King wrote:I was trying to make my own Color to use with awt. I useed the statement public static final Color purple = new Color(255,0,255);
When I try to use Color.purple it says it cannot reference purple.
Can somebody tell me what I am not understanding about this?

Colour.purple is a reference to a field of the class Color. Just replace 'Color' with the name of the class where you definied your 'purple' field.

Winston
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
purple is defined in your class, not in the Color class, so you'd refer to it as "NameOfMyClass.purple".

As an aside, it's good practice to use all-uppercase names for constants such as this, like PURPLE. That way, everyone reading your code recognizes it as such.
 
Paweł Baczyński
Bartender
Posts: 2087
44
Firefox Browser IntelliJ IDE Java Linux Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do not try to use Color.purple because you did not add a new field to the Color class.
Just use your purple variable.

BTW, by convention public static final variables should be written using capital letters, so your definition should be
Color PURPLE = new Color(255,0,255);
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JavaRanch machine-gun replies. I win.

Winston
 
Campbell Ritchie
Marshal
Posts: 56578
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The Color class is not final, so you can create your own class.Numbers for colours found here.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!