title: How do I use an image as an object in Java?
body: <p>I am trying to create a game and don't know how to use an image as the player controlled character. I have a class that makes the object the user controls, and everything works,the thing is I had to base the user controlled character as a rectangle for its positioning and movement, so it has to stay as a rectangle, which is where my searching comes up short. Basically I am wondering if I can jsut essentially paste an image over the rectangle I have and have it stick to it. here is my character class:</p>
  
  <pre><code>class Flyer{
      static int panelWidth = 2200;
      static int panelHeight = 1800;
  
      public static Rectangle flyer = new Rectangle(panelWidth / 2 - 100, panelHeight / 2 - 100, 20, 20);
      public static Rectangle flyer2;
      public static int vertical;
      public int startingY = 0;
      public int newY;
  
      Flyer(){
          super();
      }
  
  
      public void repaint(Graphics g) {
          int panelWidth = 2200;
          int panelHeight = 1800;
  
          if (vertical == startingY) {
              startingY = flyer.y;
  
              g.setColor(Color.red);
              g.fillRect(flyer.x, startingY, flyer.width, flyer.height);
          } else {
              newY = startingY + vertical;
              g.setColor(Color.red);
              g.fillRect(flyer.x, newY, flyer.width, flyer.height);
          }
      }
  }
  </code></pre>