简体   繁体   中英

Java - Basic, How do I get a custom colour working?

I know this is simple to do but for some reason I can't get it working. I'm trying to create a custom colour in Java and it doesn't seem to be working.

import java.awt.Color;

Color deepGreen = new Color(34, 139, 34);
bar.changeColour(Color.deepGreen);

I've googled it and I can't work it out, sorry if I'm being dense.

By "not working" do you mean it says deepGreen cannot be resolved? You should have

bar.changeColour(deepGreen);

instead of

bar.changeColour(Color.deepGreen);

deepGreen is a variable you have just defined, not one of the Color constants.

This is assuming changeColor() accepts a Color as an argument.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM