Net Beans can be a very easy and fun way to learn to program in the Java language. The Net Beans graphical interface makes it very easy to develop programs in Java and it can be fun and a great resource to use when you are programming. So we will start out with a very simple program so you can get used to the interface and familiarize yourself with some of the tools.
First I will give you the installation instructions because it can be tricky for a first timer who has never used Net Beans before. First you will want to get the Net Beans IDE interface downloaded you can find it at (http://java.sun.com/javase/downloads/index.jsp). You will want to click on the third option that is labeled JDK 6 with NetBeans 5.5; this will take you to a new screen with a dialog box that says something about Secure and non-secure content just click the YES button. Next you will want to select ACCEPT for the license agreement and then select the OS you are operating on, you probably want the last option which is for Windows, so check the box next to the appropriate platform and then click the orange box that says Download selected with sun download manager.
A new window will open asking if you want to save or open or cancel the program, go ahead and select save. A new window will open asking where you want to save the program, I suggest you save it on your desktop, if you are running XP you can select the desktop Icon on the left hand side of this new window and then click save. Once it is done saving then go to your desktop and open the program, it takes a few minutes to open up and you will need to click the button “Start”, it will download the program files that need to be installed.
Now you can close the Sun Download Manager and go to where you saved the files, probably My Documents since that is the default for the download manager. Go to “your” my documents and there should be a file there called JDK-6-nb-5_5-win.exe, you will want to double click this to install it. You will be greeted by a welcome screen and you will want to click next, then accept the license agreement, then click next the default location should work for the files, and then it should install for you.
Next you need to download the Visual Web Pack for NetBeans; you can get this at (www.netbeans.org/products/index.html) you will want to click the download button next to the option that says Visual Web Pack. A new screen comes up and again you will need to click the download button, it brings you to another screen and you will click on any of the “mirror” links at the top. A dialog box comes up and you will want to click save and again save to your desktop.
Go through all the installation steps again, they should all be the defaults, and once it is installed you will be ready to open NetBeans and get to programming. The NetBeans icon should be on your desktop double click it and it will open to the welcome screen. There are several things on the welcome screen that might be interest to you, depending on your skill level and wants. You can add on any additional add-on package or just read the news about what is going on in the world of NetBeans. What we are going to do is go to the top left of the screen in the Toolbar, and click file, and go to new project, as you can see you can use your short cut keys and do the same thing (CTRL + SHIFT + N). This will open a new window with some options you will want to select the top one that reads Visual Web Application, click next and then you will need to name your project, I named mine SimpleHello. All other options can remain the defaults so just click finish once you have named your program.
You will be brought to the first page of your program; it will be totally blank except for some writing in the middle of the page. This is good you are ready to start dragging components on to your page and then we will write a little code to make our first program work.
So to get started let me explain a few of the windows you are seeing. On the far left there is are two windows, One I call the project window, this window has three tabs and tells you some information about your program and you will at a later time use these tabs to get around in your program and alter more complex parts to your web application, but for now you can just click on the tabs and look around.
On the right side of the window there will be two more tabs a palette tab which we will use a lot. The palette tab has all the parts that will go into our program, you can easily drag them from the palette on to the page and they become a part of your program. Then all you need to do is alter the properties of these components and this is done through the second window which is called the properties window. You can alter every aspect of the components in the properties window; this will be used a lot for naming your components and changing the way they behave.
Now the first thing we are going to do is find the label component in the palette and drag it onto the page. Now you will want to type the text “Enter your name:” and you are done with this label. Next you will drag a Text Box from the palette and place it next to your label. In the properties window you will want to select the ID field and change it from textField1 to nameField. We will use this information later.
Next thing you will want to drag onto your page is the Static Text component, place it some place below your text box. You will want to rename this to helloText, the naming of these components will be very important later on in the program. The last component we need is a button, so drag a button some place on your page, the text will be highlighted and you will want to type something for the button, I put Click Me. Now name your button helloButton.
Once you have done all of that you will want to double click on your button, this will take us into the code view and we will be in a section of code that is labeled helloButton_action( ). Below the line that says //case name where… you will want to insert the following code.
String name = (String)nameField.getText();
helloText.setText(“Good job ” + name + ” you just created your first program”);
Notice how the intellisense picks up portions of code, if at anytime you want to use this feature then just hit the enter key when the right code appears highlighted. This will insert the proper code for you even if you haven’t finished typing the line yet. For instance when we are typing the first line and we get to the nameField and we hit the period it brings up the intellisense window. Now start typing get, notice now there are lots of options that start with get, now type a t and you will see that there are only three options. Press the down arrow once to get to the getText option and click enter, it adds the rest of the code for you. This will be a handy feature once you are more familiar with the intellisense feature.
Once you have the code written then you will want to click on the Design tab, so we can go and run your program. If you have any errors the NetBeans will tell you about them when you try to go back to design view. Once you have made it to design view we will want to click on the green triangle that says Run Main Project, or just click (F6), again if you have any errors it will let you know. A web browser should open up with your components on it, now enter your name and click the button and you should get a message that says you have written your first program, with your name in the sentence.
This completes the tutorial on a simple Java web program. Not to hard at all, just the basic steps in using some components, naming them, and passing some data to a variable and displaying the data entered by a user. If you would like more info on NetBeans or Java check out these websites (www.netbeans.org) and (www.java.sun.com).