Here you can find the source of generatePoint(Shape region)
public static Point generatePoint(Shape region)
//package com.java2s; //License from project: Open Source License import java.awt.*; public class Main { public static Point generatePoint(Shape region) { Rectangle r = region.getBounds(); double x, y; do {//from www .j a va 2 s.c o m x = r.getX() + r.getWidth() * Math.random(); y = r.getY() + r.getHeight() * Math.random(); } while (!region.contains(x, y)); return new Point((int) x, (int) y); } }