I am currently learning java and I have problem and can't find anything about it. I got an "javax.imageio.IIOException: Can't read input file!" I don't understand what I did wrong : this is my code :
public class FirstWindoww extends JFrame {
JTextField usernameText = new JTextField(30);
private JPanel panel1;
private JPanel panel2;
public FirstWindoww() {
super("FROGGER GAME");
JFrame frame = this;
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
this.setLocationRelativeTo(null);
this.setSize(400, 400);
this.setLayout(new FlowLayout());
panel1 = (JPanel) this.getContentPane();
panel1.setBorder(BorderFactory.createEmptyBorder(30,30,10,30));
panel1.setLayout(new FlowLayout());
panel2 = (JPanel) this.getContentPane();
panel1.setBackground(Color.GREEN);
JPanel startingGame = new JPanel();
this.setVisible(true);
JLabel username = new JLabel("ENTER YOUR NAME");
panel1.add(username);
panel1.add(usernameText);
usernameText.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
System.out.println("Bouton cliqué !");
}
});
JButton start = new JButton("START");
start.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
frame.remove(panel1);
frame.add(panel2);
frame.validate();
}
});
panel1.add(start);
JButton exit = new JButton("EXIT");
exit.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
}
});
panel1.add(exit);
JButton help = new JButton("HELP");
help.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
}
});
panel1.add(help);
try {
// Load the background image
BufferedImage img = ImageIO.read(new File("C:\\Users\\N\\Documents\\testGUI\\srce\\grenouille"));
this.setContentPane(new JLabel(new ImageIcon(img)));
} catch (IOException exp) {
exp.printStackTrace();
}
JLabel imageLabel = new JLabel();
imageLabel.setIcon(new ImageIcon("C:\\Users\\N\\Documents\\testGUI\\src\\grenouille.png"));
panel1.add(imageLabel);
}
Here are the error in a picture and you can see the fields on the right enter image description here
Thank you for taking the time to read this. Have a very good day everyone :) !!!