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 General. Under Projects, select Java Class Library. Click Next.
  2. Under Project Name, enter 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 File/Folder. Under Categories, select Java Classes. Under File Types, select JApplet or Applet. Click Next.
  5. Under Class Name, enter the name of your applet. Under Package, 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 Project 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