Matt
Matt

Reputation: 1

How to put paint component pieces on top of a background in Java?

We have a group project where we must create a turn based, 2 player, grid game for class, i.e. Chutes and Ladders. The whole project is done except for the fact that when we bring the background image up, the players pieces get painted behind the background, and are therefore not visible. Is there a way to get the pieces to show up on top of the background image? We are using imageIO for the image, GridLayout for the Grid, and then using PaintComponent to place the pieces on the grid. When we do not have the background image, the pieces show up on the Grid flawlessly.

Upvotes: 0

Views: 67

Answers (1)

Hovercraft Full Of Eels
Hovercraft Full Of Eels

Reputation: 285405

using PaintComponent to place the pieces on the grid

  • Make sure to call the super's paintComponent(...) method first thing in your paintComponent override.
  • Make sure that your paintComponent method has no program logic inside of it.
  • Sometimes it's better to place your pieces in ImageIcons and the Icons in JLabels, and then place your JLabels on a Grid of JPanels. For example.

For more help, post code and give more details. To be honest, I'm a little surprised that you haven't even posted your paintComponent method code.

Upvotes: 2

Related Questions