Java Swing Tutorial - Java Shape.contains(double x, double y)








Syntax

Shape.contains(double x, double y) has the following syntax.

boolean contains(double x,  double y)

Example

In the following code shows how to use Shape.contains(double x, double y) method.

import java.awt.Point;
import java.awt.Shape;
import java.awt.geom.Rectangle2D;
//from   w w  w.j  ava 2 s .c o m
public class Main {
  public static void main(String[] args) throws Exception {
    Shape s = new Rectangle2D.Double(0, 0, 72, 72);
    
    System.out.println(s.contains(30,40));
  }

}

The code above generates the following result.