So I'm trying to make this 2D game, with a character and an enemy. I have seperat JPanels for the background, the enemy and the movable character. I tried putting all of them in the same JFrame, on top of each other, but the enemy JPanel and the character JPanel are not on top of each other, but rather next to each other. I also tried LayeredPane but couldn't really get it to work.
This is the code for the JFrame, if necessary, I could provide the code for the other classes aswell (keying is the character, enemy is the enemy (duh) and Images is the background):
import javax.swing.*;
import java.awt.*;
public class Display extends JFrame{
public JPanel gp = (JPanel) getGlassPane();
public Images i;
public static Keying k;
public Enemy en;
public Display() {
i = new Images();
gp.setVisible(true);
k = new Keying(this, i);
i.loadImages();
en = new Enemy(k);
gp.setLayout(new GridLayout(1,1,0,0));
this.setLayout(new GridLayout(1,1,0,0));
gp.add(k);
this.add(i);
gp.add(en);
}
}