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;
}
}
Soo,你在哪裏設置場景內容? – n247s
view.setNamen(namen); view.setScores(scores); – m4t5k4
很抱歉,我可能不太清楚。你能發佈HighScore視圖類嗎?此外,你甚至使用了什麼前端api?現在它的巫術找出爲什麼場景(內容)不能正常工作...... – n247s