0

I don't want to use magic numbers. I'm setting a color to a jpanel background, Is there a possible way to use a color instead of

panel.setBackground(new color (255,255,255));

Thanks

Hash
  • 7,726
  • 9
  • 34
  • 53

2 Answers2

1

Color class has static fields for most common colors. You can also define your own colors as constants and use them throughout your code.

Color myColor = new Color(1,2,3);
panel.setBackground(Color.RED);
panel.setBackground(myColor);
Juvanis
  • 25,802
  • 5
  • 69
  • 87
0

You can use the static fields of the Color class.

Ex:- BLACK , WHITE

panel.setBackground(Color.BLACK);
Rahul
  • 44,383
  • 11
  • 84
  • 103