|
|
|
|
|||||||||||||||||||||||||||||||||
|
|
|
||||||||||||||||||||||||||||||||||
|
Generating a Java Applet and a Java Application |
|
|
|||||||||||||||||||||||||||||||||
|
Press the "Convert to Java" button to generate the Java code based on project files. The files generated in this process are output to the designated directory or to the same directory as the original files depending on the option set. The generated code will operate as both an applet or an application depending on how it is used. When it is invoked from an html file it runs as an applet. It operates as an application when invoked using the java.exe from a command-line, shortcut, or from another application. You do not need to decide at generation time how you will use it. The following example shows the original Visual Basic files for an application named Project1 and the corresponding Java files that are produced. It assumes that the module names are the same as the file name. The file name for the Java files always corresponds to the name of the Form, Module, Control, Type, etc. A .java and .class file is also generated for every User Defined Type contained in the Forms, code modules and classes.
Project1.class can be used as an applet by loading the Project1.html in a browser or it can be run as a stand-alone
application by executing " The Run button runs the application as a stand-alone application in the Java Virtual Machine (JVM). Any runtime errors will be displayed in the DOS box that is also displayed. Run as an AppletTo test the application as an applet, open the Project1.html file in a browser. The startup form is embedded into the sample Project1.html page. You can cut and paste the html code beginning with <object and ending with </object> (for Java 1.1 it is <applet and </applet>) into any other html file. If you are using the Java 2 swing option then your browser will need the Java 2 plugin. It is installed by default when you install the Java 2 SDK. The applet contains references to all of the Forms in your project. Upon creation, it invokes the startup form specified in the project properties and embeds it in the html page. Trouble shooting: If you get an error running the applet, you may not have everything installed correctly. It is useful to open the Java Console to see a more detailed explanation of the error condition. If you are using Java 2, the default option, you will need to run the Start->Programs->Java Plugin Control Panel menu item. If you do not have this then you have not installed the Java 2 JRE or SDK. On the Java Plugin Control Panel check the Show Java Console checkbox and the Java Console will display each time you run a Java 2 Applet in your browser. If you are running as a Java 1.1 Applet then it will use the builtin Java engine and you should launch the Java Console by clicking on the Communicator->Tools->Java Console menu item in Netscape or the View->Java Console menu item in Internet Explorer. If you see a class not found error then you do not have the Java class library installed properly. See the deployment section. Run as stand-alone applicationPress the Run Java button on the toolbar or you can execute the resulting standalone Java Application from the
DOS prompt using the following method. Java invokes the Java Virtual Machine and executes Support For User Defined TypesUser defined types (UDT) can be created in Visual Basic using the "Type" statement. Each UDT is generated as its own Java class by the same name as the name of the Type. |
|