jigsaw puzzle

hello all, i am a noob who is programming a jigsaw puzzle game, am pretty much done with piece creation (which took me hell of time) and clipping its associate piece of image by using paint, and paint context.

i created the piece using bezier technique (generalPath), used it as clip then i filled it with the image as a paint type.

now i dont knw how to proceed to select the drawn piece. (the graphic object)
can some1 please give am idea.

http://s24.postimg.org/4wu8nwc45/image.png

http://s4.postimg.org/g2gegym19/image.png

my codes are as follows :

all the piece are stored into an array : JigsawPiece jpArray[nColumn ][nRow ]
my piece class

public class JigsawPiece {

int pID;
int[] arrayLocation= new int[2];
int topTab=0;
int rightTab=0 ;
int bottomTab=0;
int leftTab=0;
int tileWidth= 50;
int tileHeight= 100;
double wTileRatio= (double)tileWidth/100;
double hTileRatio= (double)tileHeight/100;
Point p1 = new Point();
Point p2 = new Point();
Point p3 = new Point();
Point pieceLocation = new Point(0,0);
Point pieceBoundOffset = new Point(0,0);
Point pieceBoundCoordinates = new Point(0,0);
Rectangle pieceBound ;
BufferedImage img=null;
JigsawPaint jPaint;
GeneralPath jPiece= new GeneralPath();
JigsawPiece northPiece = null;
JigsawPiece eastPiece = null;
JigsawPiece southPiece = null;
JigsawPiece westPiece = null;
}

/*
SKIPPING THE SETTER AND GETTER METHODS to avoid filling the screen for nothing.... they wrk totally fine ;)
*/

JigsawPaint class:

public class JigsawPaint implements Paint, PaintContext{

	protected BufferedImage bImg ;
	protected Rectangle recClip ;
	protected Rectangle userBounds;
	protected Point initialBound;
	public JigsawPaint(){
	
	}//close public declaration
	
	public JigsawPaint(BufferedImage img, Rectangle r, Point p){
		bImg = null;
		recClip = new Rectangle();
		userBounds = new Rectangle();
		bImg = img;
		recClip.setRect(r);
		initialBound = new Point(p);
	}//close public JigsawPaint with arguments 
	public void setRecClip (Rectangle r){
		
		recClip.setRect(r);
	}//close setRecClop
	
public ColorModel getColorModel(){
	
	return bImg.getColorModel();
	
}//close ColorModel

public PaintContext createContext(ColorModel colormodel, Rectangle rectangle, Rectangle2D rectangle2d, AffineTransform affinetransform, RenderingHints renderinghints)
{
    userBounds.setRect(rectangle);
    return this;
}

public int getTransparency()
{
    return 1;
}
public Raster getRaster(int i , int j, int k , int l){
	
	int i1 = (i - userBounds.x) + initialBound.x;
    int j1 = (j - userBounds.y) + initialBound.y;
	
    return bImg.getRaster().createChild(i1, j1, k, l, 0, 0, null);
    
    
}//close getRaster

my paintPuzzle method found in my jPanel :

public void paintPuzzles(Graphics2D g2){
		
	g2.setStroke(new BasicStroke(2F));
	System.out.println("PUzzle painting ...");
	if (jpArray!=null){
		int count=0;
		for(int i =0;i<nRow;i++){
			
			
			for(int j =0;j<nColumn;j++){
				count++;
				System.out.print(count+" - ");
				System.out.println(jpArray[i][j].pieceLocation);
				g2.translate(jpArray[i][j].pieceLocation.getX(), jpArray[i][j].pieceLocation.getY());
				g2.setPaint(Color.white);
				
				g2.draw(jpArray[i][j].jPiece);
				g2.setPaint(jpArray[i][j].jPaint);
				g2.fill(jpArray[i][j].jPiece);
				
				
				g2.translate(-jpArray[i][j].pieceLocation.getX(), -jpArray[i][j].pieceLocation.getY());
				
				
			
			}//close j loop
		}//close i loop
	}//close if statement

	}//close paintPuzzle

Guys plz help, how can i select these graphic objects ??
google’s result is pretty confusing

Every piece has to have a bounding box so you can check the mouse coordinates to see if they intersect with a given piece. The Java class Rectangle would be a perfect fit.
http://docs.oracle.com/javase/7/docs/api/java/awt/Rectangle.html
Specifically the method contains(int x, int y).

thanks, was waiting till i finish implementing it before i answer u, which is done. like in my code above, i already created the bounding boxes and all, i was hesitatant to go through this logic, and thanks to u, i confirmed that i though right.
been a great help :slight_smile: