• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

display mouse pointer coordinates

 
Ranch Hand
Posts: 510
Google Web Toolkit Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Master Rancher
Posts: 5110
38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Google Web Toolkit Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks I managed to solve the problem..Your idea was gr8.
 
A "dutch baby" is not a baby. But this tiny ad is baby sized:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic