Hi all,
I'm wondering if someone can help me. I am trying to write a basic program which involves a square moving across a JPanel in a random direction, and the user needs to click on the square to get a point.
Now I have everything up and running but I cant seem to get the program to work correctly when clicking on the square. Its hit and miss whether the program registers whether the picture has been clicked on. This is the code i'm using to detect whether the square has been hit - can anyone suggest why its not working please!!!
public Rectangle area()
{
return new Rectangle(getXPos(), getYPos(), boxSize, boxSize);
}
public void hit (int mouseX, int mouseY)
{
Point mousePoint = new Point();
mousePoint.x = mouseX;
mousePoint.y = mouseY;
if(myPicture.area().contains(mousePoint))
{
myPicture.hit();
}
}