Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Drawing a point on a JPanel

Is there any way to draw a Point on a JPanel using the java.awt.Graphics class? I couldn't find any such method. Well, there are many methods for drawing lines and other shapes, (e.g .drawLine(int x1, int y1, int x2, int y2), but does Graphics lack the implementation to draw the most basic geometrical object?

like image 354
JavaNewbie_M107 Avatar asked Dec 01 '12 04:12

JavaNewbie_M107


2 Answers

Yes It does lack it, you're gonna have to use:

.drawLine(x1, y1, x1, y1)

(the same location for both source and destination points)

like image 119
mostafa.S Avatar answered Oct 30 '22 00:10

mostafa.S


You can use this:

Graphics2D g2d = (Graphics2D)g;
g2d.drawOval(5, 5, 100, 100);

Or you can check this article

like image 43
bhuang3 Avatar answered Oct 30 '22 01:10

bhuang3