Reputation: 21
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.
Upvotes: 0
Views: 427
Reputation: 324118
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 );
Upvotes: 1