About my class and why it's not detecting java.awt.Color?
Solution 1
To elaborate on the given answers:
The setColor method requires a single Color
object as its parameter. You cannot pass it Color
, as that is a class, and you cannot pass it red
, as that doesn't mean anything to the compiler (it tries to find a variable named red
).
The trick is to access the static variable Color.red
or Color.RED
(which is a Color
object), and pass it into the method, as the other answers have done. As mentioned in another answer, the javadocs for Color
may help you here.
Solution 2
java.awt.Color has a constant red
. It should be
pencil.setColor(Color.red);
in line 33. Have a look at its the javadoc for Color
.
Solution 3
You have a syntax error where you have pencil.setColor(Color, red);
This line should be: pencil.setColor(Color.RED);
By the way welcome to SO!
allenlistar
Updated on June 05, 2022Comments
-
allenlistar almost 2 years
I've got a issue with the program I'm writing - this is an APCS A class so there is an APCS.lib - it includes the DrawingTool Class that is used in the program. I'm having issues with the import java.awt.Color statement:
There is a driver that is executed for the entire program but my question is in the line import java.awt.Color; and line 33 - pencil.SetColor(Color, red); . Not sure my drjava is not detecting that java.awt.color import and still giving me a "cannot find symbol/variable error." The program draws a house.
//Name£∫ Allen Li //Date: Monday, September 9th, 2013 //Purpose: Using apcslib to draw a house on with a piece of paper and pencil. import apcslib.*; import java.awt.Color; public class DrawHouse{ private DrawingTool pencil; private SketchPad paper; /** * Basic constructor for DrawHouse. * Instantiates paper and pencil to basic * values. */ public DrawHouse(){ paper = new SketchPad(300, 400); pencil = new DrawingTool(paper); } /** * The draw method for the DrawHouse class. * This method will run all of the * commands necessary to draw the house. * */ public void draw(){ // draw the main house pencil.setWidth(3); pencil.setColor(Color, red); pencil.down(); pencil.move(-100,0); pencil.move(-100,100); pencil.move(100,100); pencil.move(100,0); pencil.move(0,0); //door pencil.up(); pencil.move(-20,0); pencil.down(); pencil.move(-20,50); pencil.move(20,50); pencil.move(20,0); //roof pencil.up(); pencil.move(-100,100); pencil.down(); pencil.move(0,150); pencil.move(100,100); //window left pencil.up(); pencil.move(-70, 60); pencil.down(); pencil.move(-40, 60); pencil.move(-40, 90); pencil.move(-70, 90); pencil.move(-70, 60); //window right pencil.up(); pencil.move(70,60); pencil.down(); pencil.move(40,60); pencil.move(40,90); pencil.move(70,90); pencil.move(70,60); pencil.up(); } }