• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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.
 
Rancher
Posts: 5008
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.
 
This one time, at bandcamp, I had relations with a tiny ad.
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic