So I am faced with a situation that I have been stuck with for an hour.
Here’s my situation: I want to add an image that says “Life:” separate from my game canvas very much like this game Legend of Zelda for the NES.

Problem is: my code still only shows my game canvas.
public class Game extends Canvas {
private Game(){
JFrame container = new JFrame("Arcade Shooter Clone");
panel = (JPanel)container.getContentPane();
panel.setLayout(new BorderLayout());
panel.add(this,BorderLayout.CENTER);
ShipLifeTitle shipLifeTitle = new ShipLifeTitle();
panel.add(shipLifeTitle,BorderLayout.SOUTH);
}
}
public class ShipLifeTitle extends Sprite {
private Image image;
public ShipLifeTitle()
{
try
{
image = ImageIO.read(new File("src/Ship/shipLifeTitle.PNG"));
}
catch(IOException e)
{
e.printStackTrace();
}
}
@Override
public void draw(Graphics g) {
// TODO Auto-generated method stub
g.drawImage(image, 200, 200, null);
}
}
public class Sprite extends Component implements GameComponent {
public Vector2D position;
public Vector2D velocity;
@Override
public void update(long milliseconds) {
// TODO Auto-generated method stub
}
@Override
public void draw(Graphics g) {
// TODO Auto-generated method stub
}
}
In you
ShipLifeTitlepanel, you need to override itsgetPreferredSizemethod.This will give
BorderLayoutsome hints as to how you want the panel to be laied out