title: Drawing two circles with different positions and colors in java
body: <p>I'm new to Java and I want to try some graphic things with it. I want to generate two circles with two different colors and different positions. My code:</p>
  
  <p>Paint Class:</p>
  
  <pre><code>package de.test.pkg;
  import javax.swing.*;
  
  public class paint {
  
      public static void main(String[] args) throws Exception{
  
          JFrame frame = new JFrame("Titel");
          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          Circle d = new Circle();
          Circle r = new CircleRed();
          frame.add(d);
          frame.add(r);
          frame.setSize(600,200);
          frame.setVisible(true);
  
      }
  
  }
  </code></pre>
  
  <p>Circle class</p>
  
  <pre><code>package de.test.pkg;
  import java.awt.*;
  import java.awt.geom.*;
  import javax.swing.*;
  
  
  public class Circle extends JPanel {
  
      private double iconRadius = 100;
      private Color defaultColor = new Color(89,104,99); 
      private int positionX = 0;
      private int positionY = 0;
  
      private Ellipse2D iconBody = new Ellipse2D.Double(getPositionX(),getPositionY(),iconRadius,iconRadius);
  
      public Icon(){
  
      }
  
      public Color getDefaultColor() {
          return defaultColor;
      }
  
      public void setDefaultColor(Color defaultColor) {
          this.defaultColor = defaultColor;
      }
  
      public int getPositionX() {
          return positionX;
      }
  
      public void setPositionX(int positionX) {
          this.positionX = positionX;
      }
  
      public int getPositionY() {
          return positionY;
      }
  
      public void setPositionY(int positionY) {
          this.positionY = positionY;
      }
  
      public void paintComponent(Graphics g) {
          Graphics2D g2d = (Graphics2D)g;
          super.paintComponent(g2d);
          this.setBackground(new Color(255,255,255));
  
          g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
          g2d.setPaint(getDefaultColor());
          g2d.draw(iconBody);
          g2d.fill(iconBody);
      }
  
  }
  </code></pre>
  
  <p>CircleRed class</p>
  
  <pre><code>package de.design.pkg;
  import java.awt.Color;
  
  public class CircleRed extends Circle {
  
  private Color defaultColor = Color.RED;
  private int positionX = 120;
  private int positionY = 0;
  
  public CircleRed() {
  }
  
  public Color getDefaultColor() {
      return defaultColor;
  }
  
  public void setDefaultColor(Color defaultColor) {
      this.defaultColor = defaultColor;
  } 
  
  public int getPositionX() {
      return positionX;
  }
  
  public void setPositionX(int positionX) {
      this.positionX = positionX;
  }
  
  public int getPositionY() {
      return positionY;
  }
  
  public void setPositionY(int positionY) {
      this.positionY = positionY;
      }
  
  }
  </code></pre>
  
  <p>The Result is that the Circles have the same positions.</p>
  
  <p>My questions are:</p>
  
  <ol>
  <li>Why do they have the same positions?</li>
  <li>Is this a good way to do that or are there better solutions? I want to use a class so please don't gave me answers with do all that paint thing in the Main.</li>
  <li>Is there a better way to hold the position. Maybe in an array? But how should the setter and getter look like if I want to return <code>array[position]</code>?</li>
  <li>If I want to set the Position from the Main function. How can I do this?</li>
  </ol>