作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我制作了一款类似于打地鼠的游戏。你必须点击“x”而不是痣。我想随机更改“x”的位置,但出现以下错误“错误:找不到符号方法 getButton1()”(zufall 在德语中是随机的意思)
线程 zufallsXThread = new Thread() {
@Override
public void run() {
while (fail > 3) {
try {
Thread.sleep(500);
} catch (InterruptedException e) {
e.printStackTrace();
}
runOnUiThread(new Runnable() {
@Override
public void run() {
int zufall = (int) (Math.random() * 9) + 1;
if (zufall == 1) {
this.getButton1().setText("x");
} else if (zufall == 2) {
this.getButton2().post("x");
} else if (zufall == 3) {
this.getButton3().setText("x");
} else if (zufall == 4) {
this.getButton4().setText("x");
} else if (zufall == 5) {
this.getButton5().setText("x");
} else if (zufall == 6) {
this.getButton6().setText("x");
} else if (zufall == 7) {
this.getButton7().setText("x");
} else if (zufall == 8) {
this.getButton8().setText("x");
} else if (zufall == 9) {
this.getButton9().setText("x");
}
}
});
}
}
};
最佳答案
从调用方法中删除 this
关键字。
if (zufall == 1) {
getButton1().setText("x");
}
并更改 run 方法内的所有内容。
关于java - 打地鼠 - 线程中的 setButton,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44805292/
我制作了一款类似于打地鼠的游戏。你必须点击“x”而不是痣。我想随机更改“x”的位置,但出现以下错误“错误:找不到符号方法 getButton1()”(zufall 在德语中是随机的意思) 线程 zuf
我是一名优秀的程序员,十分优秀!