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:
- Choose File > New Project.
Under Categories, select General. Under Projects, select Java Class Library.
Click Next.
-
Under Project Name, enter the name of your application.
Change the Project Location to any folder on your computer.
- Click Finish. The IDE creates the project folder.
- 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.
-
Under Class Name, enter the name of your applet.
Under Package, enter the package to which the applet
will belong.
- Click Finish. The IDE creates the applet in the
specified package. The applet opens in the Source editor.
-
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);
}
}
- Right click the project node in the Projects window and choose Build Project from the pop-up menu.
- 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