I am working on a java graphics project. So basically, i need to draw a shape on my JPanel
using mouse clicks. 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?
I am trying to implement it in my paintComponent
method.
but i dont know how to fill the irregular polygon.
Polygon
object to represent the Shape
.draw(Shape)
method to paint the Shape outline and the fill(Shape)
method to fill the 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 );
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.