Applets in NetBeans IDE

Introduction

This article describes the procedure to create an Applet using the NetBeans IDE. There are mainly two ways to create an Applet in the NetBeans IDE, they are:

  • To simply write the code of the Java applet in the NetBeans Editor and "Run File" as usual.
  • Otherwise we can use the GUI Builder to make the task easer than writing long code.

In this article we will be using the GUI Builder to create an Applet siince everyone might be familiar with the traditional method of writing the code and executing it.

 Creating Project

The following is the procedure to start a new project:

  • Click on "File" -> "New Project".

18.1.jpg

  • A wizard named "New Java Application" will appear, write the project name as "NewApplet" and unselect the Create main class checkbox.
  • Finally click on the "Finish" button.
  • You will see that your project is added in the project window.

18.2.jpg

Creating JApplet Form

The following is the procedure to create a jApplet Form:

  • In your project window, expand your project node and right-click on the "Source Package" folder.
  • Select "New" -> "Other...", then a file named "New File" will appear.

18.3.jpg

  • In that select "Swing GUI Forms" in category and jApplet Form in file type, then click on the "Next>" button.
  • Now write the class name and package name as indicated in the following screenshot and click on the "Finish" button.

18.4.jpg

Now you will be able to see the design view of your applet.

18.5.jpg

And in the project window the packages that are included are also visible now.

18.6.jpg

Adding the perfect compiler Version to the project

This step is very important to be applied; to do it, we need to use the following procedure:

  • Right-click on the project and select "Properties".
  • Select the Source/Binary Format as JDK 7 and then click on the "Ok" button.

18.7.jpg

Making the GUI Builder to use the correct Libraries

  • In the navigator window, right-click on the "Form NewApplet" and go to properties.
  • In this properties window set the Layout Generation Style as "Swing Layout Extension Library".

18.8.jpg

Adding Components to Your Applet

  • Choose and add the components to your applet from the palette window.

Output Screenshots:

18.9.jpg

When we click on the first "Click" button:

18.10.jpg

When we click on the second "Click" button:

18.11.jpg

Up Next
    Ebook Download
    View all
    Learn
    View all