Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
有没有办法JPanel使用java.awt.Graphics类在 a 上绘制一个点?我找不到任何这样的方法。好吧,绘制线条和其他形状的方法有很多,(例如.drawLine(int x1, int y1, int x2, int y2),但Graphics缺少绘制最基本几何对象的实现吗?
JPanel
java.awt.Graphics
.drawLine(int x1, int y1, int x2, int y2)
Graphics
是的,它确实缺少它,您将不得不使用:
.drawLine(x1, y1, x1, y1)
(源点和目标点的位置相同)
你可以使用这个:
Graphics2D g2d = (Graphics2D)g; g2d.drawOval(5, 5, 100, 100);
或者你可以查看这篇文章