Creating an Applet

See Also

If you want to run an applet in a web application, you must create it in a separate Java Class Library project and then package the applet's JAR file in the web application.

To create an applet:
  1. Choose File > New Project. Under Categories, select Java. Under Projects, select Java Class Library. Click Next.
  2. In the Project Name text field, type the name of your application. Change the Project Location to any folder on your computer.
  3. Click Finish. The IDE creates the project folder.
  4. Right-click the project node in the Projects window or Files window and select New > Other. Under Categories, select Java. Under File Types, select JApplet or Applet. Click Next.
  5. In the Class Name text field, type the name of your applet. In the Package text field, enter the package to which the applet will belong.
  6. Click Finish. The IDE creates the applet in the specified package. The applet opens in the Source editor.
  7. Type the code for your applet class, such as the following:
         import java.applet.Applet;
         import java.awt.Graphics;
    
         public class MyApplet extends Applet {
             public void paint(Graphics g) {
                 g.drawString("Hello world!", 50, 25);
             }
         }
    
  8. Right click the project node in the Projects window and choose Build from the pop-up menu.
  9. Run the applet.
See Also
Packaging a Resource in a WAR File
Setting Permissions for an Applet
Accessing an Applet from a JSP Page

Legal Notices