Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

display mouse pointer coordinates

 
Yahya Elyasse
Ranch Hand
Posts: 510
Eclipse IDE Google Web Toolkit Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all
I have an Applet that implements MouseListener and MouseMotionListener events.

In mousePressed() method i'm writing code to draw a point on the location where the mouse was pressed.

In mouseMoved() method (the problem) I'm trying to write code so that the coordinates of the mouse pointer are displayed...I managed to do the following :

int xMove,yMove;
public void mouseMoved(MouseEvent e) {

Graphics g=getGraphics();
//erase old mouse location coordinates
g.setColor(this.getBackground());
g.drawString("+",xMove,yMove);
g.drawString(""+Integer.toString(xMove)+","+Integer.toString(yMove)+"",xMove+10,yMove-10);


xMove = e.getX();
yMove = e.getY();
//paint new mouse location coordinates
g.setColor(Color.black);
g.drawString("+",xMove,yMove);
g.drawString(""+Integer.toString(xMove)+","+Integer.toString(yMove)+"",xMove+10,yMove-10);


}





the problem of this method is that when i move pointer over an already painted point ; this point is erased from the screen !

I want the mouse pointer to be showed over all painted shapes on my applet.
can you give me a hint on how to do that ?

many thanks.
 
Norm Radder
Bartender
Posts: 1526
14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
An idea: don't clear the graphics context between the calls to paint(). In AWT you override the update() method to call the paint() method. Normally update() clears the graphics before calling paint().
 
Yahya Elyasse
Ranch Hand
Posts: 510
Eclipse IDE Google Web Toolkit Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks I managed to solve the problem..Your idea was gr8.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic