Hello all, I am making a 2D Scroller game, and I know how to accomplish it, however, having trouble setting an image to the background, no amount of videos or tutorials is helping. The image does not appear. If i can just figure this out I am good. Here is my code:
import java.awt.Graphics; import java.awt.image.BufferedImage; import java.io.File; import java.io.IOException; import javax.imageio.ImageIO; import javax.swing.*; public class BackgroundPanel extends JPanel { private BufferedImage image; public BackgroundPanel() { try { image = ImageIO.read(new File("ges.jpg")); JLabel picLabel = new JLabel(new ImageIcon(image)); setSize(300,300); setVisible(true); } catch (IOException e){} } }
thanks for any help, it's bothering meimport javax.swing.JFrame; public class Frame { public static void main(String[] args) { JFrame frame = new JFrame("Bobby"); BackgroundPanel panel = new BackgroundPanel(); frame.add(panel); frame.setVisible(true); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(500,400); } }