NetBeans is an IDE (Integrated Development Environment) for
Java programming.
It includes lots and lots of sophisticated
tools. Because of the multitude of tools, it is
easy to "get
lost" in the program. Try to stick to the basic editing tools at
first. Download version 3.6 at http://www.netnitco.lkams.kernel.org/pub/mirrors/gentoo/source/distfiles/
or here http://plato.acadiau.ca/courses/comp/dsilver/2513/demo/j2sdk-1_4_2_04-nb-3_6-bin-windows.exe
Mounting a Folder [Mount Folder] [New File] [Smart Editor] [Run Program] [GUI Design] [Auto-Code] [Events] [Initialization] [Simple] [Reference]
First you must "mount a file system". That basically means
opening a folder.
In the File menu, choose Mount Filesystem.
Choose a Local Directory and click [Next].
Find your folder and click [Finish].
Then you should see your folder in the File Systems list on the left.
New Java File [Mount Folder] [New File] [Smart Editor] [Run Program] [GUI Design] [Auto-Code] [Events] [Initialization] [Simple] [Reference]
Click File/New to create a new file. Then choose Java Class/Empty File.
Type the Name of the class (without .java) and click on your folder, and click [Finish].
Now you should see the file name in the File System list,
and the edit
window should be empty. Now you are ready to type a program.
Smart Editor [Mount Folder] [New File] [Smart Editor] [Run Program] [GUI Design] [Auto-Code] [Events] [Initialization] [Simple] [Reference]
The editor is "smart". It doesn't just accept typed text
- instead, it is constantly checking
your code as you type it. If you
make a mistake, it underlines the error and marks the line
with a red [x],
as shown near the bottom below. If you hold the cursor over the red [x],
a
little yellow message appears to tell you what is wrong. In the example
below,
we forgot the semicolon at the end of the line.
Code Help
NetBeans will also try to help you find the right command. If you type
slowly, NetBeans
might pop-up a help window, to help you find the right command
or the right way to
spell a command. You can scroll through the list
and click on the command rather than typing it.
Or just finish typing as
normal.
Brackets Help
NetBeans will highlight matching brackets, braces, or parentheses. It
also tries to help by automatically
writing the closing bracket each time
you type an opening bracket. But pay attention and don't type an
EXTRA
closing bracket. Then you will have an error.
Run the Program [Mount Folder] [New File] [Smart Editor] [Run Program] [GUI Design] [Auto-Code] [Events] [Initialization] [Simple] [Reference]
To test your program, press the little green arrow - it saves, compiles and
runs the program.
Or press the [F6] key.
If there is an syntax error, the compiler error messages will
appear at the bottom of the screen.
You can double click on the message to
see the line where the error occured,
or just look at the little red x's
[x] on the left side of the editor window.
If you write a console (text-mode) app like this one, you will see the output
in the same place
as the compiler errors, but in the [I/O] window. But
you will probably write GUI apps.
GUI Designer [Mount Folder] [New File] [Smart Editor] [Run Program] [GUI Design] [Auto-Code] [Events] [Initialization] [Simple] [Reference]
If you want NetBeans to help you design a GUI app, you shouldn't start with
an empty file.
In the new file dialog, choose [GUI AWT Frame] or something
similar.
Then you'll see the GUI Designer window.
Click on the [AWT] components (don't put Swing components in an AWT Frame).
Then click on a component, like a TextField, and put it in the Frame.
Or
put a Button in the Frame. Then you will have something like this:
That's probably not what you want, but you will not be able to make the button
smaller.
You need to change the [Border Layout] to [Null Layout].
Right
click on [Frame], choose [Set Layout], and click on [Null Layout].
Now you
can click on a component and put a copy on the Frame,
and then resize the
component.
Properties
If you want to rename the components, do it in the Inspector
window.
If you want to change the default text in the
TextFields, or the label on a Button,
do that in the Properties
window.
Properties include things like the Font in a TextField, the size of the Frame,
or the background color of a Button. These can all be set in the Properties
window.
Auto-Code [Mount Folder] [New File] [Smart Editor] [Run Program] [GUI Design] [Auto-Code] [Events] [Initialization] [Simple] [Reference]
When you change properties of components, each change requires a command
to
be written in the code. These commands are auto-generated by NetBeans.
That
means you don't need to worry about the correct synatx for these commands.
But
don't change the commands directly in the code, as you could cause errors.
To
see all the commands that NetBeans has written, switch to the code view
by clicking
on the tab that doesn't say [Form]. Click on the
[Form] tab to return to design view.
Events [Mount Folder] [New File] [Smart Editor] [Run Program] [GUI Design] [Auto-Code] [Events] [Initialization] [Simple] [Reference]
To respond to the Button being clicked, you need to write some code.
Double-click
the Button, and you will be placed in the correct place in the program
where
you can write code to handle the Button event.
Now you need to type the code that responds to the Button.
In this example,
it gets the number from the left box, changes it to a double,
squares it,
and puts the answer back into the right box.
Initialization Code [Mount Folder] [New File] [Smart Editor] [Run Program] [GUI Design] [Auto-Code] [Events] [Initialization] [Simple] [Reference]
When you run the program, the window might be very small. To avoid
this,
you need to change the the starting size of the Frame. Unfortunately,
there is no
Property you can set in the Properties window. Instead,
you must go into the code
window, find the constructor (at
the top of the program), and then after the
initComponents() command,
write the resize command: setSize(450,100);
You can put any other commands you like into the constructor, but you probably
want
them after the initComponents() command.
public static void main
If you are wondering where the main method is, you'll find it at the
bottom
of the code listing. In Java, the order of methods
doesn't matter.
Keep It Simple [Mount Folder] [New File] [Smart Editor] [Run Program] [GUI Design] [Auto-Code] [Events] [Initialization] [Simple] [Reference]
If you want to know more about NetBeans, you can find tutorials on the web.
But
they will probably be written for a later version. In the later versions,
you
must create a Project before you start anything. And
then it is tricky to figure out
where your files are stored. Version
3.6 is probably easier for a beginner than version 5.0.
If you decide to use the GUI designer, it will work a bit differently than
EasyApp.
Once you get used to it, you'll be fine. But EasyApp
was written with beginners in mind -
NetBeans was developed for professional
programmers, so don't expect it to be "easy".
AWT is simpler to use than Swing. Swing has lots more components, and
gives you
a lot more control over how they function - but that means you
need to worry about
the specifics more in Swing than in AWT. Beginners
should stick to AWT.
And NetBeans runs pretty slowly on older PCs - but be patient, it will start eventually.
References [Mount Folder] [New File] [Smart Editor] [Run Program] [GUI Design] [Auto-Code] [Events] [Initialization] [Simple] [Reference]
Here are a couple references that might be helpful:
Getting Started
http://plato.acadiau.ca/courses/comp/dsilver/2513/NetBeans_Tutorial/Tutorial1/index.htm
Brief Summary
quickstart.htm
NetBeans Docs Archive
http://www.netbeans.org/kb/archive/index.html
Various Tutorials
http://faculty.ed.umuc.edu/~arnoldyl/NetBeansTutorials/
Long and Thorough
http://inf.untag-sby.ac.id/pustaka/JAVA/UsingNetBeans3.6.pdf
Way too much info - don't bother
http://www.netbeans.org/download/books/definitive-guide/