我试图在表格中设置一个值,我目前正在填充表格,其中列出了我的玩家类别中的玩家列表,我试图在表格中设置得分值但是很挣扎。我不确定如何在表格中设置值。 (每位球员有10个分数)。任何帮助将非常感谢提前感谢。
玩家等级:
import java.util.concurrent.atomic.AtomicInteger;
public class Player {
public static final AtomicInteger id = new AtomicInteger(0);
public int playerID;
public String name;
public String scoreString;
private String preference;
private String barriers;
private String[] scores ;
private int roundtotal;
private int total ;
public Player(){
this.playerID = id.incrementAndGet();
this.name = "";
this.preference = "Left";
this.barriers = "Yes";
this.scores = new String[11] ;
}
public Player( int playerID, String Name, String preference, String barriers) {
this.playerID = playerID;
this.name = Name;
this.preference = preference;
this.barriers = barriers;
this.scores = new String[11] ;
}
public int getPlayerID(){ return playerID; }
public void setPlayerID() {this.playerID = playerID;}
public String getName() {
return name;
}
public void setName(String Name) {
this.name = Name;
}
public String getPreference() {
return preference;
}
public void setPreference(String preference) {
this.preference = preference;
}
public String getBarriers() {
return barriers;
}
public void setBarriers(String barriers) {
this.barriers = barriers;
}
public void setScore(int turn, int score1, int score2) {
String scoreString = score1 + "/" + score2;
System.out.println(scoreString);
roundtotal = score1 + score2;
total = total + roundtotal;
scores[turn] = scoreString;
}
public String getScore(int whichScore) {
return scores[whichScore] ;
}
public int getTotal() {
return total ;
}
public String getScoreString(){
return scoreString;
}
@Override
public String toString () {
return "Player{" +
"id='" + playerID + '\'' +
"Name='" + name + '\'' +
", Preference='" + preference + '\'' +
", barrires=" + barriers + '\'' +
", S1=" + getScore(1) + '\'' +
", S2=" + getScore(2) + '\'' +
", S3=" + getScore(3) + '\'' +
", S4=" + getScore(4) + '\'' +
", S5=" + getScore(5) + '\'' +
", S6=" + getScore(6) + '\'' +
", S7=" + getScore(7) + '\'' +
", S8=" + getScore(8) + '\'' +
", S9=" + getScore(9) + '\'' +
", S10=" + getScore(10) + '\'' +
", Total =" + total +
'}';
}
}
表FXML:
<TableView fx:id="scoreboard" prefHeight="200.0" prefWidth="200.0" GridPane.columnIndex="1" GridPane.rowIndex="1">
<columns>
<TableColumn fx:id="nameCol" prefWidth="150.0" resizable="false" text="Player Name">
<cellValueFactory>
<PropertyValueFactory property="name" />
</cellValueFactory>
</TableColumn>
<TableColumn fx:id="scores1col" prefWidth="70.0" resizable="false" text="1">
<cellValueFactory>
<PropertyValueFactory property="scores1col" />
</cellValueFactory>
</TableColumn>
<TableColumn fx:id="score2col" prefWidth="70.0" resizable="false" text="2">
<cellValueFactory>
<PropertyValueFactory property="score2col" />
</cellValueFactory>
</TableColumn>
<TableColumn fx:id="s3" prefWidth="70.0" resizable="false" text="3">
<cellValueFactory>
<PropertyValueFactory property="getScore(3)" />
</cellValueFactory>
</TableColumn>
<TableColumn fx:id="s4" prefWidth="70.0" resizable="false" text="4">
<cellValueFactory>
<PropertyValueFactory property="getScore(4)" />
</cellValueFactory>
</TableColumn>
<TableColumn fx:id="s5" prefWidth="70.0" resizable="false" text="5">
<cellValueFactory>
<PropertyValueFactory property="getScore(5)" />
</cellValueFactory>
</TableColumn>
<TableColumn fx:id="s6" prefWidth="70.0" resizable="false" text="6">
<cellValueFactory>
<PropertyValueFactory property="getScore(6)" />
</cellValueFactory>
</TableColumn>
<TableColumn fx:id="s7" prefWidth="70.0" resizable="false" text="7">
<cellValueFactory>
<PropertyValueFactory property="getScore(7)" />
</cellValueFactory>
</TableColumn>
<TableColumn fx:id="s8" prefWidth="70.0" resizable="false" text="8">
<cellValueFactory>
<PropertyValueFactory property="getScore(8)" />
</cellValueFactory>
</TableColumn>
<TableColumn fx:id="s9" prefWidth="70.0" resizable="false" text="9">
<cellValueFactory>
<PropertyValueFactory property="getScore(9)" />
</cellValueFactory>
</TableColumn>
<TableColumn fx:id="s10" prefWidth="70.0" resizable="false" text="10">
<cellValueFactory>
<PropertyValueFactory property="getScore(10)" />
</cellValueFactory>
</TableColumn>
<TableColumn fx:id="totalCol" prefWidth="85.0" resizable="false" text="Total">
<cellValueFactory>
<PropertyValueFactory property="total" />
</cellValueFactory>
</TableColumn>
</columns>
<GridPane.margin>
<Insets bottom="15.0" left="15.0" right="15.0" top="15.0" />
</GridPane.margin>
</TableView>
答案 0 :(得分:1)
在您的控制器中,您可以(假设列定义的类型正确)
scores1col.setCellValueFactory(cellData ->
new SimpleIntegerProperty(cellData.getValue().getScore(0)));
和其他列类似。