I have a problem with this code in which I have to create a polygon, in this case I have created something like a rectangle, and in it by means of MouseListener and MouseMotionListener when executing the program and clicking on the polygon it is filled with color.
This is the code that you use to create the polygon, but with respect to filling the polygon, I have not figured out how to do it
package polipoli;
import java.awt.Graphics;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
import java.awt.Color;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class DibuPoli extends JPanel implements MouseListener, MouseMotionListener{
public void paint(Graphics g) {
int[] xs = {125, 75, 125, 185, 125};
int[] ys = {125, 75, 50, 100, 125};
g.drawPolyline(xs, ys, 5);
}
@Override
public void mouseClicked(MouseEvent me) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public void mousePressed(MouseEvent me) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public void mouseReleased(MouseEvent me) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public void mouseEntered(MouseEvent me) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public void mouseExited(MouseEvent me) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public void mouseDragged(MouseEvent me) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public void mouseMoved(MouseEvent me) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
}
This is like the second time I ask a question here, and I hope it is well formulated what I need to solve. Thanks for your attention.