第2行出现"一元运算符的操作数类型actionlistener错误!"错误,第2行和第8行出现"不兼容类型:boolean无法转换为actionlistener"错误。我在.start()的第5行也有一个错误,指出找不到符号start。有人知道这里出了什么问题吗?
private void walkjButtonActionPerformed(java.awt.event.ActionEvent evt) {
if(!walk){ //error here
walk = true; //here
timer = new Timer(40, walk);
walk.start(); //here
}
else{
timer.stop();
walk = false; //and here
}
}
private ActionListener walk = new ActionListener(){
public void actionPerformed(ActionEvent e){
if(leftLegWalk){
while (leftLegLength <=50){
leftLegLength -= 5;
}
while (leftLegLength >=20) {
leftLegLength +=5;
}
}
else {
while (rightLegLength <=50) {
rightLegLength -=5;
}
while (rightLegLength >=20) {
rightLegLength += 5;
}
}
}
};
boolean running = false;
int count = 0;
boolean wave = true;
boolean leftLegWalk = true;
boolean rightLegWalk = false;
int leftLegLength = 50;
int rightLegLength = 50;
private Timer timer;
您混淆了变量。变量CCD_ 1是CCD_。不能将其视为boolean
(使用if
测试其真值,分配true
或false
)或Thread
(调用start()
)。很难确定你想完成什么,但我认为你想要的是:
private void walkjButtonActionPerformed(java.awt.event.ActionEvent evt) {
if(!running){
running = true;
timer = new Timer(40, walk);
timer.start();
}
else{
timer.stop();
running = false;
}
}