public void init()
{
// Assign values to the rectanagle coordinates.
// Add the MouseListener to your applet
}
public void paint(Graphics g)
{
// Rectangle's color
g.setColor(Color.green);
g.fillRect(rect1xco,rect1yco,rect1width,rect1height);
g.setColor(Color.red);
// When the user clicks this will show the coordinates of the click
// at the place of the click..........[b]Why SO???[/b]
g.drawString("("+xpos+","+ypos+")",xpos,ypos);
}
This is just a part of the code.......I deleted the non essential code....
What the code is supposed to do is to listen to mouseclicks inside the green rectangle and give out the co-ordinates......
First we select green color using g.setColor(Color.green)
then we create or fill up the rectangle with green
now after selecting red color, how does the program understand that g.drawString(......) implies co-ordinates of the mouse pointer? why can't assume an arbitrary value of xpos, ypos say 0,0