java - 构造函数未定义,即使明确导入?

标签 java timer undefined

所以我在这方面逐渐积累了经验,但这个问题似乎很……奇怪,而且几乎不公平,我不知道该怎么办。为了解释,这是我的代码:

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 的构造函数和一个 SceneBranchGroup .它只有一个采用 int 的构造函数和一个 ActionListener .

关于java - 构造函数未定义,即使明确导入?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8442527/

相关文章:

java - 从扫描仪读取字符串并将其转换为字符数组

java - 编译阶段后通过 Maven 插件生成新源

java - 如何自动从html页面创建模板?

javascript - jQuery/JavaScript : How can I evaluate the validity of function arguments efficiently with a range of valid types?

Javascript AJAX 函数返回类型未定义

java - 在单独的线程中预创建对象

android - 我的计时器不工作

javascript - 如何声明定时器同时避免全局变量?

c# - 为什么值变量不改变?

javascript - electron 的 remote.getGlobal() 在 window.location.replace() 之后返回 "undefined"