title: How to fill a polygon after drawing
body: <p>I wanna draw a polygon and then fill it. My code looks like this: </p>
  
  <pre><code>@Override
      public void paint(Graphics g) {
          super.paint(g);
          Graphics2D g2d = (Graphics2D) g;
  
          if (polygons.isEmpty()) {
              return;
          }
  
          for (int j = 0; j &lt; polygons.size(); j++) {
  
              ArrayList&lt;Point&gt; ActPoint = polygons.get(j);
  
              if (ActPoint.isEmpty()) {
                  return;
          }
  
          Point a = new Point();
          a = ActPoint.get(0);
          for (int p = 0; p &lt; ActPoint.size(); p++) {
              Point b = ActPoint.get(p);
              Line2D.Double line = new Line2D.Double(a, b);
              g2d.draw(line);
              a = b;
          }
  
      }
  
  
      for (int j = 0; j &lt; polygons.size(); j++) {
          ArrayList&lt;Integer&gt; listX = new ArrayList&lt;&gt;();  
          ArrayList&lt;Integer&gt; listY = new ArrayList&lt;&gt;();
  
          for (int p = 0; p &lt; polygons.get(j).size(); p++) {
           listX.add(polygons.get(j).get(p).x );
           listY.add(polygons.get(j).get(p).y );
          }
          g.fillPolygon(convertIntegers(listX),convertIntegers (listY), polygons.get(j).size());
      }
  }
  </code></pre>
  
  <p>I don't know how too make the code so it fills the polygon only after i finished drawing it. Like if i wanna have a polygon with 5 sides, the polygon is filled only after i finished drawing all the sides. Also i'd like the polygon to be filled only when i action a button. I tried to make a function </p>
  
  <pre><code>public void fill (Graphics g){
  for (int j = 0; j &lt; polygons.size(); j++) {
              ArrayList&lt;Integer&gt; listX = new ArrayList&lt;&gt;();  
              ArrayList&lt;Integer&gt; listY = new ArrayList&lt;&gt;();
  
              for (int p = 0; p &lt; polygons.get(j).size(); p++) {
               listX.add(polygons.get(j).get(p).x );
               listY.add(polygons.get(j).get(p).y );
              }
                  g.fillPolygon(convertIntegers(listX),convertIntegers (listY), polygons.get(j).size());
  
  
  } 
  </code></pre>
  
  <p>and i tried to call it here</p>
  
  <pre><code>if (e.getActionCommand().equals("Fill")) {
  
              }
  </code></pre>
  
  <p>but i don't really know how. Please help.</p>
  
  <p>P.S. Is there other ways to fill a polygon without the fillPolygon function?</p>