export a JOGL applet and embedd into a html page
It is some time that I'm te开发者_运维百科sting opengl
with java and JOGL
. I have a good result and I wan to publish it on the web, but I have a problem. I'm in eclipse, and I'm testing an Applet with JOGL
.
EDIT: Thanks to Ricket answer it fixed this problem
first of all i have this run time error (but the program works correctly):
java.lang.IllegalArgumentException:
adding a window to a container atEDIT: but it still doesn't work:
then I found this incredibly clear page
and I did what is said. I open html with the browser, the libs are downloaded, but it stops at Starting applet AppletHelloWorld
, as that is the name I gave to my applet.
Maybe I am missing something like a main function or exporting the jar properly?
This is my main code:
public class AppletHelloWorld extends Applet
{
public static void main(String[] args)
{
JFrame fr=new JFrame();
fr.setBounds(0,0,1015,600);
fr.add(new AppletHelloWorld());
fr.setVisible(true);
}
public void init()
{
setLayout(null);
MyJOGLProject canvas = new MyJOGLProject(); //MyJOGLProject extends JFrame
canvas.run(); // this do setVisible(true)
} //....
Just as the error says, you're trying to add a window to a container. A JFrame is a window. You can't add a JFrame to anything, including a Container. I think perhaps you either don't know what a JFrame is, or don't know what a Container is.
Ideally you would have MyJOGLProject extend GLEventListener instead. Then your init function would make a new GLCanvas, add an instance of MyJOGLProject to it (via addGLEventListener), and then add the GLCanvas to your applet.
Alternatively, if you're okay with the applet popping up a JFrame, then simplify your init method:
public void init() {
setLayout(null);
MyJOGLProject canvas = new MyJOGLProject();
canvas.setVisible(true);
}
That should do it.
Use JApplet. I think that's the reason why it fails. (Use Webstart with JNLP in NetBeans)
精彩评论