Step by Step Instructions for Creating Your First Applet in NetBeans 7.2
- Choose File / New Project. Under Categories, select
Java. 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 > Other. Under Categories, select Swing GUI Forms. Under
File Types, select JApplet Form. Click Next.
- Under Class Name, enter the
name of your applet. Leave Package blank for now (default package).
- Click Finish. The IDE creates
the applet in the specified package. The applet opens in the Source
editor.
- IMPORTANT: Right click your applet's background panel (not on any component or embedded panel) and choose "Set Layout..." on the pop-up menu, then select "Absolute Layout".
- Add several components (click
component, click on design panel; OR right-click on design panel and
choose Add From Palette).
- Repeat step 7 as necessary
(see below for instructions for specific components).
- To Run - Right click on
Projects.../<appletname>.java select
Run File (or SHIFT-F6)
Step by Step Instructions for Posting Your First Applet to the Web
1. Create
JAR File:
- Right click the
project node in the Projects window and choose Clean
and Build from the contextual menu.
- Create HTML File (Only needs
to be uploaded once since the JAR file contains the “actual” project)
- Right click on
Projects.../<appletname>.java
select Run File (or SHIFT-F6)
- Edit automatically
generated HTML test file (should be in <projdir>\build\<projname>.html) as followed:
1. remove
'codebase="..."' property in APPLET tag
2. add
'archive="<projname>.jar"' property
to APPLET tag
- (NOTE: Every time do
a Clean and Build this file will be deleted, and every time you run the
project it will be recreated!)
- Copy JAR file (should
be in <projdir>\dist\<projname>.jar) and edited html to web server
Component-specific Instructions
to add icon images to buttons or labels
(to get automatically bundled in the JAR file)
1. Copy
GIF or JPG to \src directory.
2. Select
icon... property of component.
3. Click
the downward arrow following the “icon” property, and select the desired image
from the pull-down menu.
to populate a JComboBox
1. First
add the combo box to the panel. Then edit the 'model' property.
to add a Menu
1.
First add a MenuBar to the JApplet.
2.
Right click on the JMenuBar object in the
Inspector, and select Add Menu (to add another menu.
3. To
add items to a menu, expland the JMenuBar
object in the Inpector, right click on the JMenu, choose Add From Palette > Menu Item
to add a nested JPanel
1.
Add the Panel to Display.
2.
Add contained components. Note that the Panel will appear very small
until you start adding things into it.