wood burning stoves 2.0*
The moose likes Swing / AWT / SWT and the fly likes How to draw points in Java? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "How to draw points in Java?" Watch "How to draw points in Java?" New topic
Author

How to draw points in Java?

George Ren
Ranch Hand

Joined: Aug 17, 2002
Posts: 58
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


THINK!
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8836
    
    7

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.


"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
Craig Wood
Ranch Hand

Joined: Jan 14, 2004
Posts: 1535
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to draw points in Java?
 
Similar Threads
Graphs support in Java.
Tree and drawing within the same panel
Drawing graphs for mathematical functions using Java
Graphs support in Java.
Want to add Horizontal and vertical scroll bar in my code