如何让JTextField显示Enum状态的字符串。例如,我想调用一个Enum并让JTextField显示其当前状态,例如WON或LOST。
最底层的是我想要的那个。
die1.setText(Integer.toString(craps.die1));
die2.setText(Integer.toString(craps.die2));
sum.setText(Integer.toString(craps.sum));
point.setText(Integer.toString(craps.point));
status.setText();
感谢。
答案 0 :(得分:3)
假设您有一个类似
的枚举enum Status{
WON,
LOSS
}
使用name
上的JTextField
方法打印如下所示。
Status gameStatus=getGameStatus();// Get the game status
switch(gameStatus){
case WON:
status.setText(Status.WON.name());
break;
.... similar for all status.
}