i'm trying to write a game that show a background and a player on screen simultaneously using 2 different classes.
here are the relevant parts of the program, or at least i think
public WorkingTitle2(){
super("Working Title");
setSize(550,429);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
loadPictures();
loadSounds();
pp = new PaintP();
pb = new PaintB();
add(pb);
add(pp);
setVisible(true);
addKeyListener(new ButtonListener());
}
private class PaintB extends JPanel{
public void paintComponent(Graphics g){
super.paintComponent(g);
g.drawImage(background,0,0, this);
}
}
private class PaintP extends JPanel{
public void paintComponent(Graphics g){
super.paintComponent(g);
g.drawImage(player2,playerX,playerY, this);
}
}//close paintComponent
public static void main (String[ ] args)
{
WorkingTitle2 wt = new WorkingTitle2();
}
can someone tell me why doesn't this work? only 1 of the image shows.