2017-11-30 8 views
-1

私は読んだ座標ファイルを持っていて、そのファイルから座標をとり、各座標を最後まで読み込んでオブジェクト/オブジェクトのポイント。どのように私は点を描画し、すべての座標を書き出すことなく線を接続するために、そのメソッドを呼び出すだろうか?ループおよび読み取りテキストファイルJavaFX |どのように点を描画して線を結ぶ方法を呼び出す方法

try { 

    // create the file reader instance 
    FileReader fReader = new FileReader(fileName); 

    // create a scanner to scan through the file 
    Scanner scan = new Scanner (fReader); 


    // loop 
    while (scan.hasNext()) { 
      int i = 0; 
      int x = scan.next(); 
      int y = scan.next(); 
      Point[] = null; 
      array[i] = point; 

      i++; 
     } 


    // close the reader 
     fReader.close(); 
} catch (IOException e) { 
    System.out.println(e.getMessage()); 
    } 
    return 0; 
} 
+1

の線に沿って何かを試してみてください?あなたが試したことを見てみましょう。 – Steven

+0

'Canvas'や' Nodes'を使っていますか? – Sedrick

+0

描画線:http://www.java2s.com/Tutorials/Java/JavaFX/0040__JavaFX_Line.htm – Sedrick

答えて

0

のため

私のコードは、あなたのdrawメソッドです。この

//List for the dots 
    ArrayList<Circle> dotList = new ArrayList<>(); 

    try { 
     // create the file reader instance 
     FileReader fReader = new FileReader(fileName); 

     // create a scanner to scan through the file 
     Scanner scan = new Scanner (fReader); 

     // loop 
     while (scan.hasNext()) { 
      int x = Integer.parseInt(scan.next()); 
      int y = Integer.parseInt(scan.next()); 
      Circle dot = new Circle(x,y,10, Color.BLACK); 
      dotList.add(dot); 
      i++; 
     } 


     // close the reader 
     fReader.close(); 
    } catch (IOException e) { 
     System.out.println(e.getMessage()); 
    } 
    Circle previousCircle = null; 
    for (Circle circle : dotList) 
     if (previousCircle != null) 
      new Line(circle.getCenterX(), circle.getCenterY(), 
       previousCircle.getCenterX(), previousCircle.getCenterY()); 
     else previousCircle = circle; 

    return 0; 
} 
関連する問題