public void init() 
  // Assign values to the rectanagle coordinates.

  // Add the MouseListener to your applet

 public void paint(Graphics g) 
  // Rectangle's color



  // When the user clicks this will show the coordinates of the click
  // at the place of the click..........[b]Why SO???[/b]


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(
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

This question has already been answered. Start a new discussion instead.