▶Create Java Application First of all, you need to create a standard java application. The class (e.g., mypackage.MyApp) must extend JApplet and implement ActionListener. This will be the entry point for the applet version. |
▶Create Launcher Button Create a JButton in the init() method of JApplet and add MyApp as its action listener. |
▶Create User Interface Clicking the button will open the user interface (UI). Usually this can be a simple JFrame object (e.g., mypackage.MyGUI). The class provides its own main() method which will be the entry point for the standalone version. Note, that the main() method is irrelevant for the applet version. It is only called if the jar file is clicked without a web launcher. |
▶Create Web Launcher If started from inside a browser, the jar requires a web launcher. The applet tag will place the launcher button in the HTML document. This will instantiate the main panel of the UI. Note that the applet dimension should match the size of the launcher button as defined in the applet code. |
<applet code="mypackage.MyApp.class" archive="dist/MyApp.jar" width="200" height="30" />
A demonstration project (NetBeans IDE 7.1.1) can be downloaded ▷here. It countains the source code, the HTML launcher and the jar file.
No comments:
Post a Comment