I am trying to put am image for the background. When I run my code, a screen with nothing shows up and another screen with 2 buttons and the yellow background. How do I replace the yellow and put in the image that I want??
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
public class GameFrame extends JFrame {
public BufferedImage image;
public JFrame gameframe;
public JPanel panel;
public JButton b1;
public JButton b2;
public JLabel lab;
public GameFrame() {
//SETTING GAMEFRAME
gameframe = new JFrame("Poop MAN");
gameframe.setVisible(true);
gameframe.setSize(1350, 1000);
gameframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
panel = new JPanel();
panel.setBackground(Color.yellow);
//BUTTONS
panel.setLayout(null);
b1 = new JButton("CONTROLS");
b2 = new JButton("START");
b1.setBounds(500, 200, 150, 150);
b2.setBounds(500, 400, 150, 150);
b1.setPreferredSize(new Dimension(50, 50));
b2.setPreferredSize(new Dimension(30, 50));
panel.add(b1, BorderLayout.SOUTH);
panel.add(b2, BorderLayout.SOUTH);
gameframe.add(panel);
gameframe.repaint();
}
public void ImagePanel() {
try {
image = ImageIO.read(new File("unnamed"));
} catch (IOException ex) {
}
}
public BufferedImage getImg() {
return image;
}
}