Bonjour pour tous,
j'ai crée un code java contenant une interface graphique qui comporte une barre d'outil
l'interface est:
Interface m
la barre est :
jToolBar1
Mon but est de poursuivre les positions de la barre d'outil lors de sa deplacement
Mais quand je deplace la barre ,le code provoque des erreurs que je n'ai pas pu les corriger
alors j'ai crée cette classe
et dans la fonction main située dans la classe Interface:
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 import java.awt.* ; import java.awt.event.*; import java.util.*; import java.applet.Applet; import javax.swing.JToolBar; class ActionMouse extends MouseAdapter { Interface c ; JToolBar jToolBar; ActionMouse(Magic_Med c) {this.c=c; } ActionMouse( JToolBar jToo) { jToolBar =jToo; } public void mousePressed(MouseEvent e) { Object source = e.getSource(); if (source == c.jToolBar1) if (source == c.jToolBar1) {System.out.println("la barre") ; System.out.println ("x="+e.getX() +"y="+e.getY() ); } public void mouseReleased(MouseEvent e) { Object source = e.getSource(); if (source == c.jToolBar1) if (source == c.jToolBar1) {System.out.println("la barre") ; System.out.println ("x="+e.getX() +"y="+e.getY() ); } }
voici les erreurs :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8 public static void main(String[] args) throws Exception { Interface m = new m(); m.addMouseListener(new ActionMouse(m )); m.jToolBar1 .addMouseListener(new ActionMouse(m.jToolBar1 )); }
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85 java.lang.NullPointerException at ActionMouse.mousePressed(ActionMouse.java:29) at java.awt.AWTEventMulticaster.mousePressed(AWTEventMulticaster.java:222) at java.awt.Component.processMouseEvent(Component.java:5097) at java.awt.Component.processEvent(Component.java:4897) at java.awt.Container.processEvent(Container.java:1569) at java.awt.Component.dispatchEventImpl(Component.java:3615) at java.awt.Container.dispatchEventImpl(Container.java:1627) at java.awt.Component.dispatchEvent(Component.java:3477) at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:3483) at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3195) at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3128) at java.awt.Container.dispatchEventImpl(Container.java:1613) at java.awt.Window.dispatchEventImpl(Window.java:1606) at java.awt.Component.dispatchEvent(Component.java:3477) at java.awt.EventQueue.dispatchEvent(EventQueue.java:456) at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:201) at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:151) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:145) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:137) at java.awt.EventDispatchThread.run(EventDispatchThread.java:100) java.lang.NullPointerException at ActionMouse.mouseReleased(ActionMouse.java:38) at java.awt.AWTEventMulticaster.mouseReleased(AWTEventMulticaster.java:232) at java.awt.Component.processMouseEvent(Component.java:5100) at java.awt.Component.processEvent(Component.java:4897) at java.awt.Container.processEvent(Container.java:1569) at java.awt.Component.dispatchEventImpl(Component.java:3615) at java.awt.Container.dispatchEventImpl(Container.java:1627) at java.awt.Component.dispatchEvent(Component.java:3477) at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:3483) at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3198) at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3128) at java.awt.Container.dispatchEventImpl(Container.java:1613) at java.awt.Window.dispatchEventImpl(Window.java:1606) at java.awt.Component.dispatchEvent(Component.java:3477) at java.awt.EventQueue.dispatchEvent(EventQueue.java:456) at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:201) at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:151) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:145) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:137) at java.awt.EventDispatchThread.run(EventDispatchThread.java:100) read.java:100)
s'il vous plait aider moi pour corriger ces erreurs
et Merci
Partager