I was trying to make a new color in java using
Color temp = new Color(foo.getBackground());
and it kept telling me cannot find symbol.
But this works
Color temp = (foo.getbackground());
Why?
That's because foo.getBackground() returns a Color instance, and there's no Color constructor which takes a Color instance as an argument.
Check this link Color (Java 2 Platform SE v1.4.2).
If you want this code to work:
Color temp = new Color(foo.getBackground());
foo.getBackground() must return an integer. Since it returns an object Color you have type mismatch.
You can always do:
Color temp = new Color(foo.getbackground().getRGB());
or:
Color color = foo.getBackground();
Color temp = new Color(color.getRed(), color.getGreen(), color.getBlue(),color.getAlpha());
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With