• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

display mouse pointer coordinates

 
Ranch Hand
Posts: 510
Google Web Toolkit Eclipse IDE 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.
 
Master Rancher
Posts: 3921
36
  • 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
Google Web Toolkit Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks I managed to solve the problem..Your idea was gr8.
 
Who knew that furniture could be so violent? Put this tiny ad out there to see what happens:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic