Bonjour,

J'aimerais tracer un trait en pointillés en utilisant DrawLine. J'ai vu sur les forums et sur le site de Java qu'on pouvait utiliser BasicStroke, mais je ne sait pas du tout à quoi correspond les paramètres.

J'ai mis dans mon code
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
Stroke stroke = new BasicStroke(epaisseur, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 0,new float[] {trait, espace}, 0);
((Graphics2D) g).setStroke(stroke);
avec trois variables epaisseur l'épaisseur du trait, trait la longueur de chaque morceau de trait et espace la distance entre chaque morceau de trait, mais comme je m'en doutais cela ne marche pas car Eclipse m'affiche un joli message rouge auquel je ne comprend rien :

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
Exception in thread "AWT-EventQueue-0" java.lang.IllegalArgumentException: dash lengths all zero
	at java.awt.BasicStroke.<init>(Unknown Source)
	at Ligne.dessiner(Ligne.java:118)
	at Fenetre.paintComponent(Fenetre.java:37)
	at javax.swing.JComponent.paint(Unknown Source)
	at javax.swing.JComponent.paintToOffscreen(Unknown Source)
	at javax.swing.BufferStrategyPaintManager.paint(Unknown Source)
	at javax.swing.RepaintManager.paint(Unknown Source)
	at javax.swing.JComponent._paintImmediately(Unknown Source)
	at javax.swing.JComponent.paintImmediately(Unknown Source)
	at javax.swing.RepaintManager.paintDirtyRegions(Unknown Source)
	at javax.swing.RepaintManager.paintDirtyRegions(Unknown Source)
	at javax.swing.RepaintManager.seqPaintDirtyRegions(Unknown Source)
	at javax.swing.SystemEventQueueUtilities$ComponentWorkRequest.run(Unknown Source)
	at java.awt.event.InvocationEvent.dispatch(Unknown Source)
	at java.awt.EventQueue.dispatchEvent(Unknown Source)
	at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
	at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
	at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
	at java.awt.EventDispatchThread.run(Unknown Source)
Comment faut-il faire en fin de compte pour tracer un trait en pointillés?

Sur le site de Java, ils mettent en exemple
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
final static float dash1[] = {10.0f};
final static BasicStroke dashed = new BasicStroke(1.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10.0f, dash1, 0.0f);
g2.setStroke(dashed);
A quoi correspondent les 10.0f et cie ?

Merci d'avance pour votre aide !