I'm trying to change the background image of my JFrame, but I'm having difficulties. Here is 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 error:
Can not make a static reference to the non-static method setContentPane (Container) from the type JFrame