• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to draw points in Java?

 
George Ren
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,everybody
I want to draw a point wherever in my panel, and I want to make the point visible and I can handle mouse events on it. How can I achieve this? By using Java 2D API? What classes in this API can I use?
Thanks!

Have a nice day
 
Joe Ess
Bartender
Posts: 9313
10
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can use any class you want. However, you may find it most useful to extend JPanel and override it's paint method with one that draws your point via java.awt.Graphics.drawRect with a height and width of one.
Then you can make your JPanel a MouseListener and when you get a mouse click, compare the coordinates of the click with the coordinates of your point.
The Java Tutorial: Creating a GUI covers these concepts and much more.
 
Craig Wood
Ranch Hand
Pie
Posts: 1535
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic