Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Program color scheme controlled by a Colors class: object or enum?  RSS feed

 
Chuck Geiger
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm writing a rather large program with lots of classes and potentially lots of JFrames. Could I have one class devoted to establishing the primary selection of colors that will be repeated throughout the program? That way, rather than remembering each color definition, I can just code something like Colors.TitleFont to represent the color of the title of each window, and Colors.InputPanelBg to represent the background of any input window. I have not found examples of this on-line, but it seems reasonable. Would a Colors object or an Enum work for this?

Here is my attempt, but Eclipse says "The constructor GSCOLORS(String) is undefined."


I am still rather a newbie at Java, but would greatly appreciate any suggestions.
 
Darryl Burke
Bartender
Posts: 5167
11
Java Netbeans IDE Opera
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Chuck Geiger wrote:Eclipse says "The constructor GSCOLORS(String) is undefined."

I concur. I see only one constructor, and that takes a Color argument. Not a String.
 
Chuck Geiger
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK, I get that. I replaced the string "0xa29292" with Color(220,192,192) inside the parentheses, but Eclipse is still not happy.
Now the error message is "The method Color(int, int, int) is undefined for the type GSCOLORS." I don't understand because that is the java.awt color specification. Sorry if this is a dumb question.
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Chuck Geiger
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A huge thanks. That's perfect!
 
Chuck Geiger
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oops, spoke too soon. That did allow my new enum class to compile, but now I am not able to use it.
The compiled enum (deleted some of the choices, but you get the idea) is below. My problem now is that when I go to a different class and first declare "GSColors color;" and then include a statement such as "lblTitle.setForeground(color.TITLEFONT);" Eclipse says that the method "setForeground" can only accept Color arguments, not a GSColors argument. Is there any way to convince it that GSColors is passing a Color?
 
Paul Clapham
Sheriff
Posts: 22374
42
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Chuck Geiger wrote:Is there any way to convince it that GSColors is passing a Color?


Well, no, because it isn't. I'm not sure what you mean by "passing" there, but at any rate a GSColors object isn't a Color, so you can't use it as if it were one. You need a Color object there.

But you wrote a method which gets a Color from a GSColors... do you remember why you did that?
 
Chuck Geiger
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ahhh! Got it. Sorry, I'm still struggling with Java syntax (and terminology). The correct statement should have been:

Thanks again.
 
Darryl Burke
Bartender
Posts: 5167
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Chuck Geiger wrote:Could I have one class devoted to establishing the primary selection of colors that will be repeated throughout the program?

A better approach would be to write a custom Theme. Take a look at the source of javax.swing.plaf.metal.OceanTheme for inspiration.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!