This is my first post, I want to draw a rectangle with a blue colour, but the problem is that the method is not recognized (this thing drives me mad) can you please help me to set the colour.
Look in the API documentation for the java.lang.Color class and you will find a list of the valid constant values. And remember that Java is case-sensitive, in other words "blue" and "Blue" and "BLUE" are three different things.
This message was edited 1 time. Last update was at by Paul Clapham
Paul Clapham wrote:Look in the API documentation for the java.lang.Color class and you will find a list of the valid constant values. And remember that Java is case-sensitive, in other words "blue" and "Blue" and "BLUE" are three different things.
Color.blue and Color.BLUE are both supported. The problem is that Rectangle has no method called setBackground.
Wouldn't you override the paintComponent() method and call the fillRectangle() or similar method of the Graphics object?
Remember to write super.paintcomponent(g); as the first statement in the paintComponent method.