gpt4 book ai didi

java - 如何在循环中声明标签?

转载 作者:行者123 更新时间:2023-12-01 17:04:03 24 4
gpt4 key购买 nike

如何自动循环创建对象?为什么这段代码不起作用?

String strLbl[] = {"Model","Weight","Length","Age","Number of keys"};
JLabel lbl[] = new JLabel[5];

for (int i=0;i<strLbl.length;i++){
JLabel lbl[i] = new JLabel(strLbl[i]);
}

最佳答案

数组元素赋值不允许使用类型声明:

JLabel lbl[i] = new JLabel(strLbl[i]);

应该是

lbl[i] = new JLabel(strLbl[i]);

关于java - 如何在循环中声明标签?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26344292/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com