所以我在这方面逐渐积累了经验,但这个问题似乎很……奇怪,而且几乎不公平,我不知道该怎么办。为了解释,这是我的代码:
import java.awt.*;
import java.util.*;
import javax.media.j3d.*;
import javax.swing.Timer; //I import the Timer class here, it is accepted
import javax.vecmath.*;
import com.sun.j3d.utils.universe.*;
import com.sun.j3d.utils.behaviors.keyboard.*;
import com.sun.j3d.utils.behaviors.vp.*;
import com.sun.j3d.utils.geometry.*;
public class Scene extends BranchGroup {
public Scene () {
Transform3D translate = new Transform3D ();
translate.setTranslation (new Vector3d (0f, 0f, -10.f));
TransformGroup objTranslate = new TransformGroup (translate);
this.addChild (objTranslate);
Box box = new Box (0.7f, 0.7f, 0.7f, new Appearance());
objTranslate.addChild (box);
javax.swing.Timer timer = new javax.swing.Timer(5, this); //error message "The constructor Timer(int, Scene) is undefined"
timer.start();
}
}
代码最大的部分不要太在意,还是草稿,后面会细化。问题在于计时器,它总是返回 The constructor Timer(int, Scene) is undefined
。我已经添加了尽可能多的导入,尽可能清楚地定义了 Timer 类的导入,等等。 timer.start()
工作正常,所以我想这个类无论如何都被识别了。但是程序不会运行,因为它是未定义的。虽然是进口的。我不知道为什么。
你们中有人有想法,或者能够解释发生了什么吗?
谢谢!
最佳答案
你的 Scene
类没有实现 ActionListener
.请参阅 here here .
换句话说,Timer
类没有采用 int
的构造函数和一个 Scene
或 BranchGroup
.它只有一个采用 int
的构造函数和一个 ActionListener
.
关于java - 构造函数未定义,即使明确导入?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8442527/