Question: So i'm learning to create a java game on eclipse. I learned adding shapes and such. I also learned how to paint the shapes (change the colours) I was wondering how to add an image to the shape. This is the code for painting the rectangle.

```
public void paintColumn(Graphics g, Rectangle column)
    {
        g.setColor(Color.blue.darker());
        g.fillRect(column.x, column.y, column.width, column.height);
    }

```

Answer: 
Start by having a look at [Reading/Loading an Image](http://docs.oracle.com/javase/tutorial/2d/images/loadimage.html) for details about how to load a image, also, have a look at [2D Graphics](http://docs.oracle.com/javase/tutorial/2d/) for more details about 2D Graphics API.

Basically, you load the image, you draw it and then draw the shape around it.

![Rectangle](https://i.stack.imgur.com/731wm.png)

```
    Graphics2D g2d = (Graphics2D) g.create();
    int x = (getWidth() - img.getWidth()) / 2;
    int y = (getHeight() - img.getHeight()) / 2;
    g2d.drawImage(img, x, y, this);
    g2d.setColor(Color.RED);
    g2d.drawRect(x, y, img.getWidth(), img.getHeight());
    g2d.dispose();

```

Now, this just draws the rectangle over the image, if you want to, somehow "frame" the image instead, you could fill the rectangle, making it larger then the image, but you'd have to fill first, then draw the image

![FilledRectangle](https://i.stack.imgur.com/CdAQG.png)

```
    Graphics2D g2d = (Graphics2D) g.create();
    int x = (getWidth() - img.getWidth()) / 2;
    int y = (getHeight() - img.getHeight()) / 2;
    g2d.setColor(Color.RED);
    g2d.fillRect(x - 10, y - 10, img.getWidth() + 20, img.getHeight() + 20);
    g2d.drawImage(img, x, y, this);
    g2d.dispose();

```
Simply create a BufferedImage object:

```
BufferedImage image = ImageIO.read(filename);

```

Then instead of doing g.drawShape do:

```
g.drawImage(image, [starting x], [starting y], [image width], [image height], [image observer]);

```

In your case, you probably won't need an image observer, so you can just put `null` in that spot.

Then what would be easiest is to just draw your rectangle on top of the image. Even though the image will not actually be "inside" the the rectangle, the layered effect will make it look as if it is. You can use `drawRect` instead of `fillRect` so you just get a border around your image.

To ensure that your rectangle ends up on top of the image, and doesn't get covered since the image is the same size, make sure to put the drawRect line **after** the drawImage.

```
g.drawRect([starting x], [starting y], [width], [height]);

```

Check out these [Graphics Java Docs](http://docs.oracle.com/javase/7/docs/api/java/awt/Graphics.html#drawImage(java.awt.Image,%20int,%20int,%20int,%20int,%20java.awt.image.ImageObserver)) for more information on drawing images.