【发布时间】:2020-11-20 06:59:25
【问题描述】:
我的 javaFx 文件中有 9 个标签和 1 个按钮。我想在每次单击按钮后一一设置标签。我该怎么做?
当我第一次按下按钮时,“数字 1”标签应该改变,当我第二次按下按钮时,“数字 2”标签应该改变,我想改变所有标签
public class Controller {
@FXML
private Label lblone;
@FXML
private Label lbltwo;
@FXML
private Label lblthree;
@FXML
private Label lblfour;
@FXML
private Label lblfive;
@FXML
private Label lblsix;
@FXML
private Label lblseven;
@FXML
private Label lbleight;
@FXML
private Label lblnine;
static int number = 0;
static List<Integer> revealed_no = new ArrayList<>(9);
public void randomNo(){
number = 1 + (int)(Math.random()*((9-1)+1));
}
public void randomlist(){
int i = 1;
while ( !(revealed_no.contains(number)) && (i <= 9)){
randomNo();
revealed_no.add(number);
i++;
}
}}
这是我在控制器中的代码。
【问题讨论】:
-
将所有标签名称添加到一个字符串数组中,每次点击显示标签增加索引时保持当前索引;顺便说一句stackoverflow.com/help/how-to-ask
标签: arrays button javafx label