| Select New from the file menu | |
| Select Applet from the New tab. | |
| File in the Project dialog | |
| The first Application Wizzard window allows you to set libraries and whether or not this can run as a standalone. Delete the package name (circled), so you can easily use in a HTML document anywhere. | |
| If you want your project to run both as an applet and an application make sure to check the can run alone checkbox. Make sure to add the following code to the end of the main (note here that frame is the name of the JFrame generated by the program. Without this code your application will not close properly. | |
frame.addWindowListener(
new WindowAdapter(){
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
}
); |
|
| The second Wizzard window allows you to create parameters | |
| The third Wizzard window allows you to create a test HTML file to run your applet in. | |
You may not want to use swing classes since many browsers don't have the swing plugin, to eliminate it. First delete the import javax.swing.* statement and change from a JApplet to an Applet.
import java.applet.*;
importjavax.swing.*; < **********delete this
public class Random extends JApplet {< ********* get rid of the J
In the body of the code, eliminate the "look and feel" section of the code.
// static initializer for setting look & feel
static {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
//UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
}
catch (Exception e) {}
}