private static final Color not working...

Posted on 2004-10-05
Last Modified: 2010-03-31
I have created a class called Board, which is to represent a the board for a board game. I want to set the color of the board as a constant, so that any time i want to change the board color, i can do so in one location. I also want all instances of the board class to use this same color.

I assumed that the best way to do it would be similarly to how it is defined in, and did so in the following way:

private static final Color BOARD_COLOR = new Color(255, 255, 175);

However, when running the program, it draw using a pale offwhite color, regardless of what numbers I use in new Color(). Even when I set it equal to Color.cyan, it still draws the same pale offwhite.

What am I doing wrong? My other uses of private static final seemed to work without there something special about colors?
Question by:iggames
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
LVL 92

Expert Comment

ID: 12233061
how do you use the BOARD_COLOR?

Author Comment

ID: 12233253
I call


in the function

private static final BufferedImage createBoardImage()

createBoardImage makes a BufferedImage of proper size, sets color to BOARD_COLOR, and draws the board using that color
LVL 92

Assisted Solution

objects earned 40 total points
ID: 12233288
should be fine, can you post some example code to demonstrate the problem.
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


Accepted Solution

tomboshell earned 60 total points
ID: 12235940
in the function createBoardImage you always set the color to BOARD_COLOR, both are final static which should be ok.  As I see it you aren't allowing for the color to change.  I assume that you are always recreating the entire board by recalling this method which only sets the one color.  Try introducing a new variable, call it something like currentColor and create some getter/setters for it.  Have this currentColor initally set to the  BOARD_COLOR and then whenever you need a new color call the setter method for the currentColor and recreate/repaint it.  


private static final Color BOARD_COLOR = new Color(255, 255, 175);

private static Color currentColor = BOARD_COLOR;

public static Color getCurrentColor(){
  return currentColor;
public static void setCurrentColor(Color c){
  currentColor = c;
private static final BufferedImage createBoardImage(){
   // whatever else

  // the return image

Author Comment

ID: 12283923
it didn't fix the problem, but i don't feel like spending the time trying to narrow down what the problem is. i only use the color in one line of code, so i just put it in manually there. thank you for your responses, though.

Expert Comment

ID: 12284253
Sorry that it wasn't solved that quick.

Featured Post

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Android development question 2 109
How do I remove an object from a 3 62
Facing this issue for maven proxy setting 2 45
Eclipse for Java EE development 2 68
INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
In this post we will learn different types of Android Layout and some basics of an Android App.
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
Suggested Courses

751 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question