Thank you for the suggestions as to why the Frame was not displaying. I have content displaying now with the following code (in a subclass in a main method with nothing being extended, though the class which has the main method is extending JPanel), but not correctly:
case start:
JPanel mapFrame = new JPanel();
mapFrame.setPreferredSize(new Dimension(950, 950));
mapFrame.setBackground(Color.CYAN);
mapFrame.setVisible(true);
mapFrame.add(new Main());
JPanel statBar = new JPanel();
statBar.setBackground(Color.BLACK);
statBar.setPreferredSize(new Dimension(400, 950));
JFrame fullBox = new JFrame();
fullBox.getContentPane().setLayout(new BorderLayout());
fullBox.setPreferredSize(new Dimension(1350, 950));
fullBox.getContentPane().add(statBar, BorderLayout.EAST);
fullBox.getContentPane().add(mapFrame, BorderLayout.WEST);
fullBox.setResizable(true);
fullBox.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
fullBox.setVisible(true);
fullBox.pack();
Previously, I had the following code instead of what I included above (in a subclass in the main method), which was working perfectly in displaying a background image and a player, whose position is updating with key input:
case start:
JFrame mapFrame = new JFrame();
mapFrame.pack();
mapFrame.setSize(1350, 1000);
mapFrame.setResizable(false);
mapFrame.setLocationRelativeTo(null);
mapFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
mapFrame.add(new Main());
mapFrame.setVisible(true);
My paint method for the background and player is as follows (in the class extending JPanel):
public void paint(Graphics g){
super.paint(g);
Graphics2D g2d = (Graphics2D) g;
g2d.drawImage(getBackgroundImage(), 0, 0, this);
((Penguin)player).draw(g2d);
public BufferedImage getBackgroundImage(){
ImageIcon i = new ImageIcon(getClass().getResource(background));
Image image = i.getImage();
BufferedImage scaledImage = new BufferedImage(950, 950, BufferedImage.TYPE_INT_ARGB);
Graphics2D g2 = scaledImage.createGraphics();
g2.drawImage(image, 0, 0, 950, 950, null);
g2.dispose();
return scaledImage;
}
The fullBox Frame needs to be repainted continuously, as the mapFrame contains the player character and points to be collected and the statBar will later contain text that will also be updating the time, and points. I tried removing the background colour of the mapFrame and it is just the default colour of the JPanel. When I include the colour, there is a small white box that is fixed in position above the cyan - kind of strange.