Drawing a point on a JPanel
40,357
Solution 1
You can use this:
Graphics2D g2d = (Graphics2D)g;
g2d.drawOval(5, 5, 100, 100);
Or you can check this article
Solution 2
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)
Author by
JavaNewbie_M107
I'm a high school computer student learning Java.
Updated on July 09, 2022Comments
-
JavaNewbie_M107 almost 2 years
Is there any way to draw a Point on a
JPanel
using thejava.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 doesGraphics
lack the implementation to draw the most basic geometrical object?