隔江千里
基于 Marco13 在他的评论中提到的解决方案,我想出了这个自定义drawOval函数。一旦笔划宽度大于直径,它基本上会从 切换drawOval到。计算函数fillOval的位置和尺寸以匹配输出。fillOvaldrawOvalpublic static void drawOval(Graphics2D g2d, int strokeWidth, int x, int y, int width, int height) { int minLength = Math.min(width, height); int maxLength = Math.max(width, height); if (minLength >= strokeWidth) { g2d.drawOval(x, y, width, height); } else { int x1 = x - (strokeWidth - maxLength) / 2 - (maxLength / 2); int y1 = y - (strokeWidth - maxLength) / 2 - (maxLength / 2); int width1 = width + strokeWidth; int height1 = height + strokeWidth; g2d.fillOval(x1, y1, width1, height1); }}这是它的样子