title: Move Ellipse and Oval Shapes in Java?
body: <p>I am trying to draw a robot using swing. The robot object is comprised of several ellipses and ovals. I need to create a method to move the robot around the JFrame depending on a user's input. I started out using rectangles for the robot, so I could just use the translate method to move it. But that doesn't exist for ellipses. How can I write a new method to move the shapes? Here is what I have so far:</p>
  
  <pre><code>public class SwingBot 
  {
  public static void main(String[] args) 
  {
      JFrame frame = new JFrame();
  
      frame.setSize(400,400);
      frame.setTitle("SwingBot");
  
      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  
      Robot r = new Robot();
  
      frame.add(r);
  
      frame.setVisible(true);
  
      Scanner in = new Scanner(System.in);
      boolean repeat = true;
      System.out.println();
      while (repeat)
      {
          String str = in.next();
          String direc = str.toLowerCase();
          if (direc.equals("right"))
          {
              r.moveBot(10,0);
          }
          else if (direc.equals("left"))
          {
              r.moveBot(-10,0);
          }
          else if (direc.equals("up"))
          {
              r.moveBot(0,-10);
          }
          else if (direc.equals("down"))
          {
              r.moveBot(0,10);
          }
          else if (direc.equals("exit"))
          {
              repeat = false;
          }
      }
  
  }
  
  
  public static class Robot extends JComponent
  {
      private Ellipse2D e = new Ellipse2D.Double(20,20,100,50);
  
      public void paintComponent(Graphics g)
      {
          Graphics2D g2 = (Graphics2D) g;
  
          g2.setColor(Color.BLACK);
          g2.fillOval(45,60,50,50);
          g2.fill(e);
  
          g2.setColor(Color.RED);
          g2.fillOval(40,40,20,20);
          g2.fillOval(80,40,20,20);
  
  
      }
  
      public void moveBot(int x, int y)
      {
  
          repaint();
      }
  
  }
  </code></pre>
  
  <p>}</p>
  
  <p>The moveBot method at the bottom is empty because it originally had the translate method called on some rectangle objects, but I changed those to ellipses and ovals. Now I don't know how to move these without the translate method.</p>