Cora Coleman Cora Coleman - 3 years ago 108
Java Question

Can you return the color of a rectangle object in java?

For example, I create a rectangle object and set its fill to black. Would I be able to check the fill color of the rectangle to determine if its white or black? Something like:

Rectangle r = new Rectangle(10.0, 10.0, 10.0, 10.0);

if (r.getFill == 'BLACK') {

Answer Source

The getFill() method returns a Paint object. Therefore, you should use equals for comparison:

Rectangle r = new Rectangle(1.0, 1.0, Color.WHITE);

if (r.getFill().equals(Color.WHITE)) {
    System.out.println("That's a white rectangle.");
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download