Welcome to the CSC Q&A, on our server named in honor of Ada Lovelace. Write great code! Get help and give help!
It is our choices... that show what we truly are, far more than our abilities.

Categories

+22 votes

Hey guys,

This is for the Lab 3G. I'm trying to create a new color. I tried using:

panel.setBackground(new Color.RED37);

When I do this eclipse marks it as an error and tries to get me to use a class constant.

asked in CSC211_Winter2018 by (8 points)

2 Answers

+17 votes

When creating a color, instead of putting RED37 as you wrote here, you instead must write a RGB (red, green, blue) value inside parentheses up to a value of 255. Here is an example which sets the background color to blue:

panel.setBackground(new Color(0,0,255));

answered by (8 points)
+11 votes

If you want to create a new color, you have to put the number correspond to these three color: RED, GREEN, BLUE (RGB). You can try out this website to find the color you want and which number to put in each color: https://www.rapidtables.com/web/color/RGB_Color.html

answered by (8 points)
...