Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How may I use g.setColor() with a variable?

843785Sep 15 2008 — edited Sep 15 2008
I'm trying to use a variable in the method setColor(), and apperars an error:

public void paint(Graphics g){

String colores = "black"; //variable storing the color

g.setColor(Color.colores);
g.drawRect(10,90,180,210);
}


ERROR:

cannot find symbol
symbol : variable colores
location : class java.awt.Color
g.setColor(Color.colores);
1 error

What's wrong ??
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 13 2008
Added on Sep 15 2008
10 comments
1,079 views