1
I’m trying to change the background image of my Jframe, but I’m having a hard time. Here’s the code:
public class teste_tamagotchi extends JFrame {
private JPanel contentPane;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
final Image backgroundImage = javax.imageio.ImageIO.read(new File("C:\\Bibliotecas\\Imagens\\galaxy-wallpaper-11.jpg"));
setContentPane(new JPanel(new BorderLayout()) {
@Override public void paintComponent(Graphics g) {
g.drawImage(backgroundImage, 0, 0, null);
}
});
} catch (IOException e) {
throw new RuntimeException(e);
}
}
});
}
And I have the following mistake:
Cannot make a Static Reference to the non-static method setContentPane(Container) from the type Jframe
Can add a [mcve] of your jframe?
– user28595
I’ll edit my code, all right ?
– Paulo