gpt4 book ai didi

java - 如何给刽子手游戏添加标签

转载 作者:行者123 更新时间:2023-11-29 05:52:36 30 4
gpt4 key购买 nike

这些是我的代码,当我从提交的文本中读取行时,标签有问题我可以添加标签“_”,它们等于程序之前的单词大小。我在创建标签时遇到问题,希望您能理解我的问题,如果可以的话,请给我一个解决方案?

 public class HangGame extends JFrame {

JLabel lbl;
JLabel word ;
private String[]myword = new String [20];
Game() {

}
void readfile () {
Properties prob = new Properties();

try{

for(int x=0; x<n; x++){
}
}}
private void initLabelPanel() {
//craete array of labels the size of the word
letterHolderPanel = new JPanel();
int count =0;

//如果你运行我的代码,这个数组 [myword.length()] 有问题,编译器找不到它。

wordToFindLabels = new JLabel[myword.length()];
//Initiate each labels text add tp array and to letter holder panel
for (int i = 0; ih; i++) {JLabel lbl = new JLabel("_");

letterHolderPanel.add(lbl);
lbl.setBounds();
}
}


}

最佳答案

myword 是一个 Strings 数组,而不是单个 String 因此您需要替换:

wordToFindLabels = new JLabel[myword.length()];

wordToFindLabels = new JLabel[myword.length];

您可以将变量重命名为 mywordArray,以避免混淆。

还使用布局管理器而不是使用绝对定位(空布局)。

参见:Doing Without a Layout Manager (Absolute Positioning)

关于java - 如何给刽子手游戏添加标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13370415/

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