bonjour,
avec ce code:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import java.awt.Graphics;
import java.awt.Toolkit;
import java.awt.Image;
 
public class NewJFrame extends javax.swing.JFrame {
 
    /** Creates new form NewJFrame */
    public NewJFrame() {        
        initComponents();        
        Toolkit kit = Toolkit.getDefaultToolkit();
        Image icone = kit.getImage("/background.jpg");
        g.drawImage(icone ,0, 0,this.getSize().width ,this.getSize().height, null);
    }
 
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">
    private void initComponents() {
 
        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
 
        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 676, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 475, Short.MAX_VALUE)
        );
 
        pack();
    }// </editor-fold>
 
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new NewJFrame().setVisible(true);
            }
        });
    }
 
    // Variables declaration - do not modify
    // End of variables declaration
Graphics g;    
}
j'ai une erreur au niveau de:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
g.drawImage(icone ,0, 0,this.getSize().width ,this.getSize().height, null);
Citation Envoyé par erreur
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
quelcun saurait-il d'ou ca vient?
merci