[英]How to fill an irregular polygon which has been drawn by mouse clicks?
I am working on a java graphics project.我正在研究 java 图形项目。 So basically, i need to draw a shape on my JPanel
using mouse clicks.所以基本上,我需要使用鼠标点击在我的JPanel
上绘制一个形状。 I have to prompt the user for the border color which is working good but I don't know how to fill the irregular polygon.. I have prompted the user for choosing the shape color using JColorChooser
but how to fill it?我必须提示用户输入效果良好的边框颜色,但我不知道如何填充不规则多边形。我已提示用户使用JColorChooser
选择形状颜色,但如何填充呢?
I am trying to implement it in my paintComponent
method.我正在尝试在我的paintComponent
方法中实现它。
but i dont know how to fill the irregular polygon.但我不知道如何填充不规则多边形。
Polygon
object to represent the Shape
.创建一个Polygon
object 来表示Shape
。draw(Shape)
method to paint the Shape outline and the fill(Shape)
method to fill the Shape使用 Graphics2D draw(Shape)
方法绘制 Shape 轮廓,使用fill(Shape)
方法填充 ShapeSimple example:简单的例子:
Polygon triangle = new Polygon();
triangle.addPoint(0, 0);
triangle.addPoint(15, 30);
triangle.addPoint(30, 0);
g2d.setColor( Color.RED );
g2d.fill( triangle );
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.