- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
这些是我的代码,当我从提交的文本中读取行时,标签有问题我可以添加标签“_”,它们等于程序之前的单词大小。我在创建标签时遇到问题,希望您能理解我的问题,如果可以的话,请给我一个解决方案?
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
,以避免混淆。
还使用布局管理器而不是使用绝对定位(空布局)。
关于java - 如何给刽子手游戏添加标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13370415/
我正在制作刽子手游戏。一切正常,我已经准备好用于使游戏失败并为猜测提供 -1 的代码。虽然将它添加到 else 语句时它会重复等于单词的长度并且它也会给出一个猜测——即使它是正确的?我看不出代码有什么
我是一名 Javascript 学生,正在开发我的 Hangman 游戏。我用于显示 secret 单词的正确破折号数量的循环不起作用。每次只显示一个破折号。感谢帮助。谢谢。 $(document).
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 关于您编写的代码问题的问题必须在问题本身中描述具体问题 — 并且包括有效代码 以重现它。参见 SSC
print("Welcome to hangman. Are you ready to have some fun?") def play(): import random List = ["ra
我刚刚开始学习 Java 作为我的第一门编程语言。 在类里面,我们被分配使用 while 和 for 循环制作一个基本的 Hangman 游戏。 到目前为止我有什么 当用户输入第一个猜测时,它确实识别
我是编程新手。我正在做一个经典的刽子手游戏,但我希望它是从节目中猜测一些角色的名字(名字和姓氏)。 我的问题:破折号打印 name 和 surname 之间的空格而不是忽略它,例如: 密语:鲁伯特·吉
我正在尝试创建一个刽子手游戏,其中每个字母都有一个按钮。我用绝对定位和多个 Action 监听器以困难的方式做到了这一点。有什么办法可以用 for 循环同时完成这两个任务吗? 另外,如何使用多态数组实
我是 Java 新手,所以这听起来可能很傻。 我正在尝试从 Java 创建一个基于 GUI 的刽子手游戏。我已经从数组创建了按钮列表,单击时它返回单个字母作为字符。我有要猜测的单词列表,每次按下按钮时
我已经研究这段代码有一段时间了。我尝试了许多不同的方法来查找玩家在随机生成的单词中正确猜测的输入的索引 - 我认为我当前编写的内容应该有效,但我担心我忽略了一个非常简单的错误。事实上,每当我运行代码时
在我的 Hangman 应用程序中,我为用户创建了一组按钮,然后从文件中随机选择 Hangman 应用程序中猜测的单词...该单词使用 JLabel 打印...但是一旦单击按钮时,应用程序会卡住。谁能
我正在为我的 C 课编程编写一个刽子手程序。我似乎不知道如何执行最后一步,即在玩家猜出所有正确的字母后停止游戏。我感觉问题出在播放功能上。 #include #include #inc
用 python 编写一个 Hangman 程序,在传入一个包含多单词字符串和单单词字符串的文件时遇到了一个问题。 文件: 你好棕色狐狸 狗 猫 水 跳跃 #initialize list wordL
所以我在玩这个游戏的特定部分时遇到了问题。这些是我的初始变量: var words = ["sugar","banana","hulk"]; var guessLeft = 12; var wrong
我是一名优秀的程序员,十分优秀!