title: Translate/Rotate/Move a graphics object without messing up the whole screen
body: <p>I'm coding a GUI that will be doing some graphics translations/rotations, etc. </p>
  
  <p>My problem is that when I try to translate my graphics,</p>
  
  <p>(a) The entire screen translates instead of my one little painted area</p>
  
  <p>(b) The old paint stays there, leaving a big paint blob instead of a translated image</p>
  
  <p>(c) If I use the <code>clearRect</code> method to allow me to avoid (b), the entire screen goes white and (a) is still a problem</p>
  
  <p>my DrawPanel class (I called it "LaunchTubeImage" for whatever reason)</p>
  
  <pre><code>private class LaunchTubeImage extends JPanel {
  
      private Color colour;
  
  
      public LaunchTubeImage(Color color) {
          super();
          this.colour = color;
      }
  
      public void paintComponent(Graphics g) {
          Graphics2D gg = (Graphics2D)g;
          double theta = (double)angle.getValue(); 
          theta = Math.toRadians(theta);
          gg.rotate(theta,tubeImage.getSize().width/2 + 10,
              tubeImage.getSize().height - 50);
  
          g.setColor(colour);
  
          g.clearRect(0,0,getWidth(),getHeight());
          g.fillRect(tubeImage.getSize().width/2,
              tubeImage.getSize().height - 100 , 10, 50);
      }
  }
  </code></pre>
  
  <p>where this is called in my code</p>
  
  <pre><code>tubeImage = new LaunchTubeImage(Color.MAGENTA);
  
  
  angle.addChangeListener(new ChangeListener(){
      public void stateChanged(ChangeEvent e) {
          tubeImage.repaint();
      }
  });
  </code></pre>
  
  <h2>Case 1: Comment out <code>clearRect</code> in that 1st block of code I posted</h2>
  
  <p><a href="http://i58.tinypic.com/2d1l5w2_th.png" rel="nofollow">http://i58.tinypic.com/2d1l5w2_th.png</a>
  Black background as desired. Not rotated yet. Looks good so far.</p>
  
  <p><a href="http://oi60.tinypic.com/1zw1sm.jpg" rel="nofollow">http://oi60.tinypic.com/1zw1sm.jpg</a>
  Rotated it with my JSpinner... you see that the previous location was not removed (and note how my buttons randomly doubled and put themselves at the top of the screen).</p>
  
  <h2>Case 2: Keeping in the <code>clearRect</code> method</h2>
  
  <p><strong>oi57.tinypic.com/2s84307.jpg</strong>
  Layout is fine so far, but I wanted the background to be black</p>
  
  <p><strong>oi57.tinypic.com/4rde8x.jpg</strong>
  Yay! It rotated. But note the weird behavior of that random "15" that appeared in my top right corner</p>
  
  <p><strong>oi58.tinypic.com/vymljm.jpg</strong>
  And finally... when I resize the window you see that my entire screen was rotated - not just the pink image I wanted to rotate</p>
  
  <p>Tips/fixes/advice? Thanks!! I hope I've provided enough information
  <strong>(P.s. if you insist on us asking clear/useful questions.... then DON'T limit the number of images you can post... :/ )</strong></p>