Une API windows permet à partir d'un tableau de points et d'un tableau d'entiers de dessiner plusieurs lignes brisées à l'écran en un seul appel. Y a-t'il quelque chose de semblable en java ? (transportable à linux bien sûr)
Patrice
Version imprimable
Une API windows permet à partir d'un tableau de points et d'un tableau d'entiers de dessiner plusieurs lignes brisées à l'écran en un seul appel. Y a-t'il quelque chose de semblable en java ? (transportable à linux bien sûr)
Patrice
Code:
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 public Shape createMultiLine(float[] x, float[] y) { if (x == null || x.length == 0) { [...] } if (y == null || y.length == 0) { [...] } int length = Math.min(x.length, y.length); Path2D.Float path = new Path2D.Float(); path.moveTo(x[0], y[0]); for (int i = 1 ; i < length ; i++) { path.lineTo(x[i], y[i]); } return path; } Shape multiline = createMultiLine(...); [...] /** * {@inheritDoc} */ @Override protected void paintComponent(Graphics g) { Graphics2D g2d = g.create(); try { g2d.setColor(Color.BLACK); g2d.draw(multiline); } finally { g2d.dispose(); }
Et hum... qu'est ce que Linux vient faire dedans ?Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 /** * {@inheritDoc} */ @Override protected void paintComponent(Graphics g) { Graphics2D g2d = g.create(); try { if (x == null || x.length == 0) { [...] } if (y == null || y.length == 0) { [...] } int length = Math.min(x.length, y.length); g2d.setColor(Color.BLACK); for (int i = 1 ; i < length-1 ; i++) { path.drawLine((int)x[i], (int)y[i], (int)x[i+1], (int)y[i+1]); } } } finally { g2d.dispose(); }
Si j'ai bien compris il faut coder l'équivalent. Il s'agit de plusieurs lignes brisées (donc on lève le crayon entre chaque ligne brisée)
Code:
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 /** * {@inheritDoc} */ @Override protected void paintComponent(Graphics g) { Graphics2D g2d = g.create(); try { if (x == null || x.length < 2 ) { [...] } if (y == null || y.length < 2) { [...] } if (n == null || n.length == 0) { [...] } int length; g2d.setColor(Color.BLACK); for (int j=0; j < n.length-1;j++){ length=n[j]; for (int i = 0 ; i < length-1 ; i++) { path.drawLine((int)x[i], (int)y[i], (int)x[i+1], (int)y[i+1]); } } } } finally { g2d.dispose(); }