title: How to get the invader moving left to right in java
body: <p>I'm creating a small space invaders project and I have the aliens constantly in a left to right loop. When they hit the end of the screen they repaint on the right side going again left to right. I have set the window size already and I have looked at various tutorials on how to make space invaders in Java, however most of them say the same thing that I have tried. Is it possible someone can point out where I am going wrong with my coding so that I know how to fix it.</p>
  
  <p>This is the code for the alien class. There are different aliens, however all the classes look pretty much the same as this one:</p>
  
  <pre><code>package spaceinvaders2;
  
  import java.awt.Graphics;
  import java.awt.Image;
  import javax.swing.ImageIcon;
  
  class Alien extends MoveObject 
  {
      Image Alien = new ImageIcon(getClass().getResource("alien.gif")).getImage();
  Alien(int x, int y, int w, int h) 
  {
      super(x, y);
      bounds.width = w;
      bounds.height = h;
  }
  
  public void paint(Graphics g) 
  {
      System.out.println("Alien generated");
      bounds.x = bounds.x - 2;
  
      if ((bounds.x + bounds.width)&lt; 0)
      {
          bounds.x = 750;
          dead = false;
      }
  
      g.drawImage(Alien,bounds.x,bounds.y,bounds.width, bounds.height, this);
  }
  }
  </code></pre>
  
  <p>Edit: My paint method is being called in the main game functionality part where it draws all the graphics. The drawing isn't the problem it is the movement of the alien which is in this class.</p>