【发布时间】:2022-11-12 11:52:36
【问题描述】:
我有一个窗格,其中包括 label1、label2、label3 和一个图标(带图像的窗格)。我复制了那个窗格,现在我在左边有 10 个窗格 5,右边有 5 个,我为窗格命名了每个不同的项目(如 left1label1、left2label1、right2label3),但我不想对每个窗格使用不同的方法。
我试图创建一组窗格,但无法弄清楚。我想要的只是管理这个窗格的简单方法。我该怎么做?
public void leftPane1Config()
{
leftPane1Label1.setText("Object");
leftPane1Label2.setText("HP:"+ hp);
leftPane1Label3.setText("EXP:"+ exp);
Image img= new Image("directory");
leftPane1Icon.setEffect(new ImageInput(img));
}
public void leftPane2Config()
{
leftPane2Label1.setText("Object");
leftPane2Label2.setText("HP:"+ hp);
leftPane2Label3.setText("EXP:"+ exp);
Image img= new Image("directory");
leftPane2Icon.setEffect(new ImageInput(img));
}
.
.And 8 other
.
我试图使用这样的东西(试图创建一个层次结构,但我做不到:'))但我不能使用 setText() 所以它不起作用。
leftPane1.getChildren().add(leftPane1Label1);
leftPane1.getChildren().get(0).setText??
然后我尝试使用这样的东西
Pane[] leftPane= new Pane[5];
leftPane[0]= new Pane();
我又想不通。
【问题讨论】: