In a nutshell, YOU have to 'be the browser' (or applet viewer) and take care of the two things that the browser/applet viewer does for the applet:
1) Providing the "Frame" background for the GUI
-- so now YOU need to, say, make a JFrame/Frame and then slap the applet into it as you would any other GUI component (by 'adding' the applet to the Frame, or for JFrame -- adding the applet to the contentPane of the JFrame)
2) Invoke the init() and start() methods of the applet, by calling those methods.
So you would, for example, create an application that was a basic GUI app, where in main() you invoke a method that builds the GUI, and in the process of building that GUI, you instantiate the applet (make a new instance of the applet class itself) and then ADD the applet -- as a Panel/JPanel -- to the GUI, then invoke the init and start methods of the applet instance, and off it goes.
The GUI application you build to *run* the applet doesn't have to do much at all, since we assume that the real work is all inside the applet code. The app you build to support the applet can be as simple as a handful of lines of code that build the frame, instantiate the applet, and call the methods on the applet.
Originally posted by Jem Edwards:
If I see a java source code for an applet how hard is it to convert it to a stand-alone program? What is the differences that stand out in the applet source code?
very difficult than the other way round(making a stand-alone to an applet based). IMHO, while building any GUI component, it should be designed for a plain stand-alone usage and then moved to the GUI mode. Reason being , while designing for the stand-alone mode, we need to define the contract/role played by the particular Class.
Jumping straight into GUI code will mess it, as the mode of thinking will be "event based".
example: good old VB programmer
Originally posted by Amy Phillips:
on the same sort of line how easy is it to get an application to be a stand alone program?
Can you get it to have an icon and everything?
When you say you want to create an application to a stand-alone program, how do you mean? (Typically the two are used synonomously.)
The typical way to achieve the "double-click-to-run" functionality is to package your code into an executable JAR file. Then, you just type "java -jar MyJarFile.jar", or, if your system is set up to recognize it, just double-click the .jar file. (Which will execute javaw -jar MyJarFile.jar, which doies not produce an output console). You can then assign an icon to the .jar file (Although I assign the icon to the shortcuts created by my installer, not to the .jar itself.)
If you want to move away from requiring the JRE, I believe that I have heard tell of a way to translate a Java program into a .exe, but that then makes it system-dependant. (Can't run the same .exe on both Unix and Windows.)