2017-03-04 15 views
0

これは数時間後に思いついたものです。悲しいことに、それは空のハイスコアシーンを私に残す。IOを上級者向けの例で実行する

​​

これは.txtファイルの外観です。

2500,Peter 
2400,Elisabeth 
2200,Josje 
1900,Sebastiaan 
1500,Petra 
1500,Jozef 
1500,Dave 
1400,Karen 
1200,Kristel 
1000,Jules 

ハイスコアは\ nで区切られています。スコアと名前は "、"で区切られています。

public class HighScoresView extends GridPane { 
private Label naamKop; 
private Label scoreKop; 

private Label[] namen; 
private Label[] scores; 

public HighScoresView() { 
    initialiseNodes(); 
    layoutNodes(); 
} 

private void initialiseNodes() { 
    naamKop = new Label("Naam"); 
    scoreKop = new Label("Score"); 
    namen = new Label[HighScores.AANTAL_HIGHSCORES]; 
    scores = new Label[HighScores.AANTAL_HIGHSCORES]; 
    for (int i = 0; i < HighScores.AANTAL_HIGHSCORES; i++) { 
     namen[i] = new Label(""); 
     scores[i] = new Label(""); 
    } 
} 

private void layoutNodes() { 
    setGridLinesVisible(true); 

    naamKop.setPadding(new Insets(2, 10, 8, 10)); 
    naamKop.setPrefWidth(120); 
    scoreKop.setPadding(new Insets(2, 10, 8, 10)); 
    scoreKop.setPrefWidth(120); 

    add(naamKop, 0, 0); 
    add(scoreKop, 1, 0); 

    for (int i = 0; i < HighScores.AANTAL_HIGHSCORES; i++) { 
     add(namen[i], 0, (i + 1)); 
     add(scores[i], 1, (i + 1)); 
     namen[i].setPadding(new Insets(5, 0, 5, 10)); 
     scores[i].setPadding(new Insets(5, 0, 5, 10)); 
    } 
} 

Label[] getNaamLabels() { 
    return namen; 
} 

Label[] getScoreLabels() { 
    return scores; 
} 

public void setNamen(Label[] namen) { 
    this.namen = namen; 
} 

public void setScores(Label[] scores) { 
    this.scores = scores; 
} 


} 
+0

すごい、あなたはシーンのコンテンツをどこで設定しますか? – n247s

+0

view.setNamen(namen); view.setScores(スコア); – m4t5k4

+1

申し訳ありませんが、私はverryクリアされていない可能性があります。 HighScoreビュークラスを投稿できますか?また、どのフロントエンド - APIを使用していますか?今、シーン(コンテンツ)が正しく機能していない理由を知るための魔術師... – n247s

答えて

0

次のものを変更して動作します。 (プレゼンタークラス)

private void updateView() { 
    String[] namen = new String[10]; 
    String[] scores = new String[10]; 
    String[] strings; 
    try { 
     Scanner scanner = new Scanner(new File(HighScoresModel.getBESTANDSNAAM())); 
     scanner.useDelimiter(System.lineSeparator()); 
     for (int i = 0;i<10;i++){ 
      strings = scanner.nextLine().split(","); 
      namen[i] = strings[1]; 
      scores[i] = strings[0]; 
     } 
     view.setNaamText(namen); 
     view.setScoresText(scores); 
    } catch (FileNotFoundException e) { 
     e.printStackTrace(); 
    } 

} 

割り当てが追加されているにもかかわらず、このクラスが完了しましたが、 (表示クラス)

public void setNaamText(String[] namen) { 
    for (int i=0;i<namen.length;i++) { 
     this.namen[i].setText(namen[i]); 
    } 
} 

public void setScoresText(String[] scores) { 
    for (int i=0;i<scores.length;i++) { 
     this.scores[i].setText(scores[i]); 
    } 
} 
関連する問題