Following my previous post here , I changed the code to :
PolygonnerJframe.java
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Point;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
import java.util.ArrayList;
import java.util.Iterator;
import javax.swing.JFrame;
import javax.swing.JPanel;
/**
*
* @author X2
*
*/
public class PolygonnerJframe
{
public static void main (String[] args)
{
JFrame frame = new JFrame("Draw polygons");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setContentPane(new DrawingPanel());
frame.pack();
frame.setVisible(true);
}
}
Now , this code results in :
And I can't understand what causes this .
The changes that I've made are : when we're done with a polygon , its coordinates are saved in the arrayList of class Polygon
, and each time that I create a new polygon , I take
the previous polygons and draw them , while drawing a new polygon .
As you can see above , something went wrong with the drawing and I can't seem to find the problem .
I'd appreciate any help .
Thanks
EDIT:
After taking into consideration what @StanislavL said , I moved those lines to mouseClicked()
, but this time I get a new screen each time that a new polygon is created without the "old" polygons .
Just a new polygon ... without the old ones