Bonjour,
J'ai l'erreur suivante au lancement de mon code
Exception in thread "main" java.lang.NullPointerException
at TestGraphic.<init>(TestGraphic.java:33)
at TestGraphic.main(TestGraphic.java:9)
Je suppose que cela vient du fait que j'utilise la classe Graphics
qui est abstraite, je serais donc sensé en hériter (et redefinir les methodes abstraites ...) pour pouvoir
utiliser ces fonctionnalités, mais cela me parrait un peu lourd.
Y a t'il un moyen plus simple pour dessiner dans mon contexte
graphique, vu mon code?
D'avance merci de vos réponsesCode:
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 import java.awt.event.*; import java.awt.*; import javax.swing.*; public class TestGraphic extends JFrame { public static void main (String[] args) { new TestGraphic().show(); } public TestGraphic () { setSize (300,200); addWindowListener (new WindowAdapter() { public void windowClosing (WindowEvent événement) { System.exit(0); } }); JPanel test2; Graphics lecontexteGr; test2 = new lePanneau(); getContentPane().add(test2); lecontexteGr = test2.getGraphics(); lecontexteGr.drawRect(5, 5, 10, 10); } } class lePanneau extends JPanel { public void paintComponent (Graphics surface) { super.paintComponent(surface); } }