Salut à tous,
j'essaye de tracer une shape polgon avec le code ci-dessous (avec un bouton) :


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
package polyg;

import java.awt.geom.GeneralPath;
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;

import java.awt.*;

public class Polyg extends Application {
 
        public void paint (Graphics g) {
        Graphics2D g2;
        g2 = (Graphics2D) g;}
  
    @Override
    public void start(Stage primaryStage) {
        Button btn = new Button();
        btn.setText("Say 'Hello World'");
        btn.setOnAction(new EventHandler<ActionEvent>() {
            
            @Override
            public void handle(ActionEvent event) {
        
                  
        GeneralPath shape = new GeneralPath();
        shape.moveTo(1, 1);
        shape.lineTo(2, 2);
        shape.quadTo(3, 3, 4, 4);
        shape.curveTo(5, 5, 6, 6, 7, 7);
        shape.closePath();
        
        Graphics2D.draw(shape);
        
        StackPane root = new StackPane();
        root.getChildren().add(btn);
        
        Scene scene = new Scene(root, 300, 250);
        
        primaryStage.setTitle("Hello World!");
        primaryStage.setScene(scene);
        primaryStage.show();
    }

   public static void main(String[] args) {
        launch(args);
          
    }
    
}
Le problème c'est qu'il ne compile pas à la ligne Graphics2D.draw(shape);.


Merci de votre aide,

A+