Win a copy of TensorFlow 2.0 in Action this week in the Artificial Intelligence and Machine Learning forum!
  • 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
  • Liutauras Vilda
  • Paul Clapham
  • Bear Bibeault
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Jj Roberts
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • salvin francis
  • Scott Selikoff
  • fred rosenberger

modify mouse position in pixels

 
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Yes another dreaded assignment......I have to, instead of drawing a filled box, give the user the position of the mouse click in pixels when the mouse is clicked on the screen. Any cluse as to how I could modify this program to do that?
Thanks, Mary Ellen

(edited by Cindy to add formatting)

[This message has been edited by Cindy Glass (edited March 31, 2001).]
 
"The Hood"
Posts: 8521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well you already have the listener set up and it already grabs the x and y coordinates for you, so all you have to do is get rid of the thing that draws the rectangle:
g.fillRect(x-5, y-5, 10, 10);
and replace it with something that displays a message. If you read the API for the Graphics class you will find a drawString() method that takes in a String and the x and y coordinate to display it at. So if you put in:
String s ="The mouse is at x=" + x + " and y=" + y;
g.drawString(s, x , y );
it should work.
 
MaryEllen Volb
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
AS always, THANKS FOR YOUR HELP!!!
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic