Introduction to Java and NetBeans 4.1
Start up the NetBeans 4.1 IDE.
o Create a Project:
General Category, Java Application
For project Name, put
For Project Location,
Uncheck "Set Main as Project"
Uncheck "Create Main Class"
To Make a GUI Frame:
Java GUI Form
Category, JFrame Form
For ClassName, use MyFirstFrame
For Location, use Source Packages
In the Inspector pane (lower left), select JFrame
ight Click, Select Layout, Absolute Layout
In the Properties Pane (lower right) are other properties
elect JFrame in Inspector pane)
itle, put: My First Java Program!
Click the Source Tab (near the top, down a few lines)
You will see all the code that was automatically generated.
It does a pretty good job of telling you what not to touch!
Change @author to your
Add the following code right after "initComponents();" in "public MyFirstFrame()":
Build & Run
Right click on
in Projects Pane and select “Set Main Project”
Build Main Project
Run / Run Main Project: It will
ask to select
Or you can Run / Run File
if MyFirstJava.java is highlighted in Projects pane
Click back to the Design Tab
Use the Palette pane in the upper right
Click JTextField, then click on the "Frame" (middle pane)
The textfield should appear on the frame
Right click on jTextField1 in the Inspector, select
type in txtNum1
Change the Text property (Lower right
) to: 100
Click JButton, then click on the "Frame"
ename it to btnOutput
Change the T
ext property to:
around and change their sizes (this
changes X, Y, Width, Height properties
Adding button handlers
ouble click on btnOutput button (on the Frame or Inspector)
It makes the handler
, takes you to the code,
icates where to type the code.
Type in: System.out.println( txtNum1.getText() );
Build and run your program. You should be saving periodically.
When you click the button, the data in the text field gets
written to the Output pane.
You can make th
e Output pane bigger and
Call me over and show me when you are done
Finished early? If yes, try:
Add a Label over the textfield with text: "Enter Num 1"
Add Another Text Field, txtNum2
nd label for it: "Enter Num 2”
with Text of "Add"
Make the handler for the
int num1 = Integer.parseInt( txtNum1.getText() );
int num2 = Integer.parseInt( txtNum2.getText() );
int ans = num1 + num2;
System.out.println( "Answer: " + ans );
Note what hap
pens if you don't have integers in the textfields
and click the Add button.
Call me over if you finish this.
Open a Beans Project
hen browse to the folder, for
lick "Open Project Folder".
Want NetBeans 4.1 on your own machine?
JDK 5.0 Update 4 with NetBeans IDE
It is a little over 127 Megabytes.
Note that this does not include the JDK help.
You need to download and install that separately.
It is at:
J2SE 5.0 Documentation
It is about 43.5 Megabytes.
Download and install it.
To “Add” it into NetBeans, in NetBeans do:
Tools / Java Platform Manager
Click on the Javadoc Tab
Click Add / Zip Folder
Browse to the folder where you installed it
, for example: