title: The movement background picture
body: <p>having a little difficulty. I am writing a small game (trying to write)) of any difficulties. That's the game code:</p>
  
  <pre><code>package Game;
  
  import java.awt.Color;
  import java.awt.Graphics;
  import java.awt.Graphics2D;
  import java.awt.Image;
  import java.awt.Toolkit;
  import java.awt.event.ActionEvent;
  import java.awt.event.ActionListener;
  import java.awt.event.KeyAdapter;
  import java.awt.event.KeyEvent;
  import javax.swing.JPanel;
  import javax.swing.Timer;
  
  public class Board extends JPanel {
  
      private final String IMAGE_PATH_DOWN1 = "C:\\Users\\дНМ\\workspace\\Game\\image\\Down_Pic1.png";
      private final String IMAGE_PATH_DOWN2 = "C:\\Users\\дНМ\\workspace\\Game\\image\\Down_Pic2.png";
  
      private final String IMAGE_PATH_RIGHT1 = "C:\\Users\\дНМ\\workspace\\Game\\image\\Right_Pic1.png";
      private final String IMAGE_PATH_RIGHT2 = "C:\\Users\\дНМ\\workspace\\Game\\image\\Right_Pic2.png";
  
      private final String IMAGE_PATH_TOP1 = "C:\\Users\\дНМ\\workspace\\Game\\image\\Top_Pic1.png";
      private final String IMAGE_PATH_TOP2 = "C:\\Users\\дНМ\\workspace\\Game\\image\\Top_Pic2.png";
  
      private final String IMAGE_PATH_LEFT = "C:\\Users\\дНМ\\workspace\\Game\\image\\Left_Pic1.png";
      private final String IMAGE_PATH_LEFT2 = "C:\\Users\\дНМ\\workspace\\Game\\image\\Left_Pic2.png";
  
      private final String IMAGE_PATH_MAP_Z = "C:\\Users\\дНМ\\workspace\\Game\\image\\Map_Z.png";
  
      private static final long serialVersionUID = 1L;
      private Thing thing;
      private Timer repaintTimer;
  
      private Image imgCs;
      private Image imgMap;
      private static int speed = 3;
  
      public Board() {
          init();
  
      }
  
      private void init() {
  
          setFocusable(true);
          setDoubleBuffered(true);
          addKeyListener(new KeyHandler());
          setBackground(Color.BLACK);
          thing = new Thing();
  
          imgCs = Toolkit.getDefaultToolkit().getImage(IMAGE_PATH_DOWN1);
          imgMap = Toolkit.getDefaultToolkit().getImage(IMAGE_PATH_MAP_Z);
  
          repaintTimer = new Timer(50, new ActionListener() {
  
              @Override
              public void actionPerformed(ActionEvent e) {
                  repaint();
              }
          });
  
          repaintTimer.start();
      }
  
      @Override
      public void paint(Graphics g) {
          super.paint(g);
  
          Graphics2D g2d = (Graphics2D) g;
  
          int width = imgCs.getWidth(this);
          int height = imgCs.getHeight(this);
  
          int scale = 4;
          speed = 3;
  
          int w = scale * width;
          int h = scale * height;
  
          //MAP START!
          int widthMap = imgMap.getWidth(this);
          int heightMap = imgMap.getHeight(this);
          int scalem = 4;
          int wm = scalem * widthMap;
          int hm = scalem * heightMap;
  
             for (int s = 0; s &lt; wm * 10; s += wm) {
                  for (int i = 0; i &lt; hm * 10; i += hm) {
                      g2d.drawImage(imgMap, thing.getX()+s, thing.getY()+i,(int) wm, (int) hm, this);
  
                  }
              }
          //MAP END
  
          g2d.drawImage(imgCs, thing.getX() * speed, thing.getY() * speed,
                  (int) w, (int) h, this);
  
          Toolkit.getDefaultToolkit().sync();
  
      }
  
      private class KeyHandler extends KeyAdapter {
  
          @Override
          public void keyPressed(KeyEvent e) {
              thing.pressed(e.getKeyCode());
              // LEFT!!!
              if (e.getKeyCode() == KeyEvent.VK_LEFT) {
                  if ((thing.getX() * speed % 2) == 0) {
                      imgCs = Toolkit.getDefaultToolkit().getImage(
                              IMAGE_PATH_LEFT);
  
                  } else {
                      imgCs = Toolkit.getDefaultToolkit().getImage(
                              IMAGE_PATH_LEFT2);
                  }
              }
              // RIGHT!
              if (e.getKeyCode() == KeyEvent.VK_RIGHT) {
  
                  imgCs = Toolkit.getDefaultToolkit().getImage(IMAGE_PATH_RIGHT1);
                  if ((thing.getX() * speed % 2) == 0) {
                      imgCs = Toolkit.getDefaultToolkit().getImage(
                              IMAGE_PATH_RIGHT1);
                  } else {
  
                      imgCs = Toolkit.getDefaultToolkit().getImage(
                              IMAGE_PATH_RIGHT2);
                  }
              }
              // DOWN!
              if (e.getKeyCode() == KeyEvent.VK_DOWN) {
                  if ((thing.getY() * speed % 2) == 0) {
                      imgCs = Toolkit.getDefaultToolkit().getImage(
                              IMAGE_PATH_DOWN1);
  
                  } else {
                      imgCs = Toolkit.getDefaultToolkit().getImage(
                              IMAGE_PATH_DOWN2);
  
                  }
  
              }
              // UP!
              if (e.getKeyCode() == KeyEvent.VK_UP) {
                  if ((thing.getY() * speed % 2) == 0) {
  
                      imgCs = Toolkit.getDefaultToolkit().getImage(
                              IMAGE_PATH_TOP1);
  
                  } else {
                      imgCs = Toolkit.getDefaultToolkit().getImage(
                              IMAGE_PATH_TOP2);
  
                  }
  
              }
  
          }
  
          @Override
          public void keyReleased(KeyEvent e) {
              //
          }
  
      }
  }
  </code></pre>
  
  <p>Another class</p>
  
  <pre><code>package Game;
  
  import java.awt.event.KeyEvent;
  
  class Thing {
  
      private final int STEP = 3;
      private int x_pos;
      private int y_pos;
  
      public void pressed(int keyCode) {
  
          switch (keyCode) {
          case KeyEvent.VK_LEFT: {
              x_pos -= STEP;
              break;
          }
          case KeyEvent.VK_UP: {
              y_pos -= STEP;
              break;
          }
          case KeyEvent.VK_RIGHT: {
              x_pos += STEP;
              break;
          }
          case KeyEvent.VK_DOWN: {
              y_pos += STEP;
              break;
          }
          }
      }
  
      public int getX() {
          return x_pos;
      }
  
      public int getY() {
          return y_pos;
      }
  
  }
  </code></pre>
  
  <p>And another class)</p>
  
  <pre><code>package Game;
  
  import javax.swing.JFrame;
  import javax.swing.SwingUtilities;
  
  public class ThingMove {
  
      private String NAME = "Title";
      private int WIDTH = 500;
      private int HEIGHT = 470;
  
      public ThingMove() {
  
          JFrame frame = new JFrame(NAME);
  
          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          frame.setSize(WIDTH, HEIGHT);
          frame.setLocationRelativeTo(null);
  
          frame.add(new Board());
  
          frame.setVisible(true);
      }
  
      public static void main(String[] args) {
  
          SwingUtilities.invokeLater(new Runnable() {
              @Override
              public void run() {
                  new ThingMove();
              }
          });
      }
  }
  </code></pre>
  
  <p>Laid back, so that the code did not take place.</p>
  
  <p>The code works, the picture shows the hero, but when he moves to the end of the box it goes under it and disappears, I would like that when you're moving image and background moved with her.To the background is not standing still and moving along with a picture of the hero.help to make it</p>
  
  <p><a href="http://pastebin.com/w4kR7FuQ" rel="nofollow">http://pastebin.com/w4kR7FuQ</a></p>
  
  <p><a href="http://pastebin.com/jKTCbUpY" rel="nofollow">http://pastebin.com/jKTCbUpY</a></p>
  
  <p><a href="http://pastebin.com/bPxSrrrR" rel="nofollow">http://pastebin.com/bPxSrrrR</a></p>