2017-08-13 20 views
-1

Javafxで一連の円を動的に作成しようとしています。円の数を入力した後、私はこの得た:enter image description herejavafxでペインにサークルを配置する

をしかし、実際に私は私の円がその位置にあることがしたい:enter image description here

ここに私のコードと任意のヒントに感謝です!!ここで

int k = 5; 
     for (int i = 0; i < nbNoeuds; i++) { 

      Noeudfx circle = new Noeudfx(k * 2, k * 2, 1, String.valueOf(i)); 
      Label id = new Label(String.valueOf(i)); 
      noeuds.getChildren().add(id); 
      id.setLayoutX(k * 2 - 20); 
      id.setLayoutY(k * 2 - 20); 
      id.setBlendMode(BlendMode.DIFFERENCE); 
      k += 10; 
      FillTransition ft1 = new FillTransition(Duration.millis(300), circle, Color.RED, Color.BLACK); 
      ft1.play(); 
      noeuds.getChildren().add(circle); 
      ScaleTransition tr = new ScaleTransition(Duration.millis(100), circle); 
      tr.setByX(10f); 
      tr.setByY(10f); 
      tr.setInterpolator(Interpolator.EASE_OUT); 
      tr.play(); 

     } 

    } 




public class Noeudfx extends Circle { 

Noeud noeud; 
Point point; 
Label distance = new Label("distance : infinite"); 
boolean isSelected = false; 
List<Noeudfx> circles = new ArrayList<>(); 

public Noeudfx(double a, double b, double c, String nom) { 
    super(a, b, c); 
    noeud = new Noeud(nom, this); 
    point = new Point((int) a, (int) b); 

    circles.add(this); 
} 

}

+0

どのような位置に配置する必要があります円ですか?それらは多かれ少なかれ私に見えます。 –

+0

はいランダムな位置にそれらを表示したい – Mira

+0

誰も私にそのplzを行う方法を教えてもらえますか? '( – Mira

答えて

0

私のソリューションです:

int nbNoeuds = Integer.parseInt(nodeID.getText()); 
     System.out.println("nnnnn" 
       + nbNoeuds); 
     final Timeline animation = new Timeline(
       new KeyFrame(Duration.seconds(.5), (ActionEvent actionEvent) -> { 

        while (noeuds.getChildren().size() <= nbNoeuds) { 
         // noeuds.getChildren().remove(0); 

         int radius =10 ; 
         noeuds.getChildren().add(
           new Circle(
             rnd.nextInt(SCENE_SIZE - radius * 2) + radius, rnd.nextInt(SCENE_SIZE - radius * 2) + radius, 
             radius, 
             Color.GRAY 
           ) 
         ); 

        } 
       }) 
     ); 
     animation.setCycleCount(Animation.INDEFINITE); 
     animation.play(); 
     animation.setOnFinished((ActionEvent actionevent) -> { 
      animation.stop(); 
     }); 

アップデート:私はこの問題は、画面中の円の数が正しい、私ではないということでした、各サークルにラベルを追加しようとしましたなぜか分からない! see here

Label id = new Label(String.valueOf(i)); 
         id.setTextFill(Color.CADETBLUE); 
         id.setAlignment(Pos.CENTER); 

         Circle circle = new Circle(
           rnd.nextInt(SCENE_SIZE - radius * 2) + radius, rnd.nextInt(SCENE_SIZE - radius * 2) + radius, 
           radius, 
           Color.GRAY 
         ); 
         Double a = circle.getCenterX(); 
         Double b = circle.getCenterY(); 
         id.setLayoutX(a - 20); 
         id.setLayoutY(b - 20); 
         id.setBlendMode(BlendMode.DIFFERENCE); 

         noeuds.getChildren().add(id); 
         noeuds.getChildren().add(circle); 
+0

どのように円ごとにラベル(ID)を設定する?? – Mira

関連する問題