Possible for a class to be both an Application and an Applet?

I want to make a class that would open either as an applet or an application depending on how it was opened. Would it be possible to do this?
[155 byte] By [Gumpngreen] at [2007-9-26 2:01:06]
# 1

It is possible. It is best to start working on it as an applet; you can then make it an application by just adding the main method.

The main method could look likepublic static void main(String[] args) {

final Applet myapplet = new MyApplet();

final Frame f = new Frame("Applet runner");

f.addWindowListener(new WindowAdapter() {

public void windowClosing(WindowEvent we) {

f.hide();

myapplet.stop();

myapplet.destroy();

myapplet.dispose();

f.dispose();

System.exit(0);

}

});

f.add(myapplet);

myapplet.init();

myapplet.start();

f.show();

}

Of course you could add listeners for other window events etc.

jsalonen at 2007-6-29 8:41:03 > top of Java-index,Archived Forums,Java Programming...
# 2
The short answer is yes, it's possible. You include a main method as usual for an application. It should create an instance of the applet and perform any appropriate initialization, including calling the applet's init method.
zaneparks at 2007-6-29 8:41:03 > top of Java-index,Archived Forums,Java Programming...
# 3
There is also an example included with the jdk 1.3/1.4, located in %JAVA_HOME%\demo\jfc\SwingSet2, which you can run as both an applet and an application.
leukbr at 2007-6-29 8:41:03 > top of Java-index,Archived Forums,Java Programming...