代码行出现错误。我应该导入什么?
我收到第 20 行错误(已标记) 对于 .createGLCanvas,我收到一条错误消息“对于 GLDrawableFactory 类型未定义方法 createGLCanvas(GLCapability)”,这是什么意思?我没有导入我应该导入的东西吗?
import javax.media.opengl.*;
import java.awt.Color;
import java.awt.Frame;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.media.opengl.GL;
import javax.media.opengl.GLAutoDrawable;
import javax.media.opengl.GLCanvas;
import javax.media.opengl.GLEventListener;
import java.awt.Canvas;
import javax.swing.JPanel;
public class Forest{//open forest
public static void main(String[] args)
{
Frame frame = new Frame("Hello World");
20: GLCanvas canvas = GLDrawableFactory.getFactory().createGLCanvas(new GLCapabilities());
frame.add(canvas);
frame.setSize(300, 300);
frame.setBackground(Color.WHITE);
frame.addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});
frame.show();
}//close forest
}
im getting an error for line 20(labeled) For .createGLCanvas i get an error saying " The method createGLCanvas(GLCapabilities) is undefined for the type GLDrawableFactory" What does this mean? Did i not import something i was suppose to import?
import javax.media.opengl.*;
import java.awt.Color;
import java.awt.Frame;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.media.opengl.GL;
import javax.media.opengl.GLAutoDrawable;
import javax.media.opengl.GLCanvas;
import javax.media.opengl.GLEventListener;
import java.awt.Canvas;
import javax.swing.JPanel;
public class Forest{//open forest
public static void main(String[] args)
{
Frame frame = new Frame("Hello World");
20: GLCanvas canvas = GLDrawableFactory.getFactory().createGLCanvas(new GLCapabilities());
frame.add(canvas);
frame.setSize(300, 300);
frame.setBackground(Color.WHITE);
frame.addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});
frame.show();
}//close forest
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这意味着 GLDrawableFactory。所以你需要弄清楚该调用什么。
It means there is no method called
createGLCanvas
on GLDrawableFactory. So you need to figure out what to call.重点是根据 javadoc 应该支持此方法:
GLCanvas createGLCanvas(GLCapabilities)
我认为您应该再次检查您的类路径。你正在使用什么罐子?你是从哪里下载的? jar版本是什么?检查所有这些,并在编写代码时使用描述您的库版本的适当 API 文档。
The point is that according to javadoc this method should be supported:
GLCanvas createGLCanvas(GLCapabilities capabilities)
I think that you should check again your classpath. What jar are you working with? Where have you downloaded it from? What is the jar version? Check all this and use appropriate API doc that describes your version of the library when you are writing code.
根据此线程,现在执行此操作的正确方法是
GLCanvas 画布 = new GLCanvas();
。这似乎代表了 API 的变化。According to this thread, the correct way to do this is now
GLCanvas canvas = new GLCanvas();
. This seems to represent an API change.