Re: JFrame as JApplet?



polsa wrote:
I was wondering if there is any way to write an application which can
be run as well as a JFrame as as a JApplet. And if so: how can I figure
out which way the application has been started?

If main() is called, then it was started as an application. I haven't done this in ages, but the following should start the applet when it is called as an application:


	public class MyAppletStub implements AppletStub {
		// implement all AppletStub methods here
		
		public MyAppletStub(String args[]) {
			// parse and remember command line
		}
	}

	public static void main(String args[]) {
		JApplet a = new MyJApplet();
		a.setStub(new MyAppletStub(args));
		a.init();
	        a.start();
	}

There are other things which might need to be adjusted. My notes tell me that I got the above from some Sun article, but I can't find the original article at the moment.

Maybe you probably better use Sun's AppletViewer to run the applet as an application.

/Thomas

--
The comp.lang.java.gui FAQ:
ftp://ftp.cs.uu.nl/pub/NEWS.ANSWERS/computer-lang/java/gui/faq
.



Relevant Pages

  • Re: Can I combine GUI & Applet?
    ... a JApplet (just add the components to the JApplet, ... Yes, I did that to produce an applet from the command line utility/GUI application, pausing only to strip out a lot of no-longer needed stuff such as mainand all the menu-bar related code. ... However, there are a few cases, mostly small applications, where it would be nice to be able to execute the same code as a command line utility, a stand-alone GUI application or embed it in a web page. ...
    (comp.lang.java.programmer)
  • Re: Metal theme in an applet.
    ... you can set a metal theme in a JApplet. ... When I run* your applet** I see red. ... Communication in such a precise environment ... http://www.PhySci.org/ Open-source software suite ...
    (comp.lang.java.gui)
  • Re: Animated GIF display in JFrame vs. JApplet
    ... The GIF animates when displayed in the JFrame by using the paintIconmethod of ImageIcon but the same code only displays a static icon in the applet. ... it works fine when the JPanel is in a JFrame but not in a JApplet. ...
    (comp.lang.java.programmer)
  • Re: Two basic questions considering Swing
    ... If you do not want an applet, extend ... > error is caused by the fact that it is an applet. ... The example from the tutorial also extends JPanel, not JApplet, I didn't notice ... But if I use a JFrame then I won't be able to put my application in a browser, ...
    (comp.lang.java.help)
  • Why doesnt this work?
    ... as an application that displays in a frame, ... when I try to run it as an applet. ... content pane the layouts are drawn on from a JFrame to a JApplet. ...
    (comp.lang.java.programmer)