III

searchcoilΛογισμικό & κατασκευή λογ/κού

15 Αυγ 2012 (πριν από 4 χρόνια και 10 μήνες)

188 εμφανίσεις

Using NetBeans

to Create and Run
a Java Application

(Updated

5 Jan 2011
)


Please note that the procedure below applies to your home / personal computer. In the
third
-
floor lab, the procedure is somewhat different, since the School of Computing’s
(SOC) co
mputers are not your own. We will show the difference between the procedure
below (for your home computer) and the SOC’s lab computers on our lab day


announced in class.



Net
B
eans
is an open source IDE (integrated development environment) available to

programmers who want to develop Java projects. Since it is an IDE, the tools needed for
editing, compiling, building, debugging, executing, and obtaining online help are all
integrated in one graphical user interface. Using these tools effectively can gre
atly
increase your productivity.


Please see the link on my web page to download the latest version of NetBeans

6.9

bundled with the latest Java, Java 6

update 20
. You must
first
download

th
is
bundle and then
install

it
prior

to running this tutorial.


1.

S
tart NetBeans

by selecting
NetBeans IDE
6.9

(or similar version)
from the
Start menu or by double
-
clicking the desktop shortcut

(recommended).
If you get
a registration box option, y
ou may register, if you like (I did).
But then you
should see a screen t
hat looks like this:

2.

There is a lot of useful information on these links. To get rid of the Start Page,
click on the X as shown via arrow.







You will see the following screen.






3. Y
ou will want at least a files pane and a pr
ojects pan. You may select these by
clicking on them in the drop down box under
Window

in the menu bar. This will
give you a screen
that looks like this above. You can hide the Services pane if
desired by clicking on it and then deleting it by selecting

the X in the tab. You will
get the following:




4
. Most activities in NetBeans are considered ‘projects,’ as all your programming
efforts will end up being projects.


5.

Under the File men
u
, select
New

Project
. You will see this New Project
Window i
n the middle of the NetBe
ans 6.8

Window








Before starting, you should create a folder on your desktop entitled COP
2551
.

Each lab
project this semester will be entitled,
projectiyouruserid
, where

i
is the number of the
project.
For example, your firs
t project would be entitled: project1jsmith. Project1
should be a subfolder within your COP2551 folder.
Each project you develop will be
located in a different
sub
folder within COP
2551
,

such as project2jsmith, etc.



To continue working on a project th
at was begun earlier

(you will see a list as you
develop projects)
, simple click on the

desired project in the Project window and continue
development.

You must also

ensure that the project you are working on is the Main
Project, and there can be only o
ne Main project

(more later on this).


6.

New Application
:
To create and run a
new
Java

application

you must first create
a project.
In the following exercise we will be creating a project named
p
roject
i
y
ouruserid
.



Now, select
JavaApplicat
ion

from the

New Project window, and then click the
Next

button below.



(If you wanted to develop Applets, you would select Java Class Library)

(Also: select some of the other options and note the Descriptions below.)










You will need to make a few changes to
the New Java Application Window that will
appear:

You will need to change entries in
Project Name, Project Location, and
Project Folder:






Here are the changes I made. You will tailor yours to your own name, etc.

Please be
careful here.


In the
Project

Name

box, I typed project0broggio. As you type in your own
project0jsmith, please note that as you type, the text box midway down on the page
inserts this Project Name in front of Main. (This is desirable and we will discuss later).



I then modifie
d the Project Location text
(the
Project Folder
textbox is filled in
automatically for you from the Project Location text). Y
ou need to
enter appropriate
settings for your project

now too.



You will need to retain your n
-
number. You can see that I have

everything on my
desktop via the Desktop, and then the folder COP2551.

When you installed NetBeans
6.8
, it ‘got’ my n
-
number. But I changed the default entries that follow to Desktop, and
then the folder COP2551, as discussed.


Mine now appears as:







Click the Finish button.



Now, we’ve got our project set up to really start to program! Here is what you should see
(using your name, of course)


You will see:

(Note that in the lower left pane, you saw a Creating Java Project…)



Note all

the information that is already supplied for you.

Please take a few moments to look these over.

Note the content of the files pane. Note that your project name and the name of your
‘main’ module is already established! Note
the skeletal code that
is already provided for
you. This will help to get you started, but you will need to understand what is actually
being provided for you, since not all IDEs provide the same help.




In

the Projects Pane, you may play

with the + and


boxes and see the ex
pansions…

Note: You may wish to take time out and access your COP2551 folder on your desktop.
You will note that a subfolder entitled projectiyouruserid will appear.


At this time, you are ready to use the IDE to develop
your Java application.

I am
providing the code for this one (project0) in order to familiarize you with the IDE a little
bit

and the use of Blackboard
for submitting your projects to me.


Please note that I use things call
scope

terminators

and rather rigid indentation
conventions, w
hich I feel all competent designers and programmers should use.

There is more information on these Standards and Conventions on my web page.


7
.

Building
the Source Code and Executing it.


The purpose of
p
roject
0

is to familiarize the student with the

procedure in using
NetBeans IDE and submitting a job to the instructor in proper format for grading. The
value of
p
roject
0 is twenty points and you should get the entire 20 points if you follow
the procedure outlined below.



Note: This is the time to

play with NetBeans to not only submit the required
project assignment, but to experiment and play around with the very powerful
IDE. The on
-
line tutorial
that comes with your CD
is excellent. Take time to
learn a few other neat things.

Perhaps you may

wish to develop an applet or two.


As mentioned, your first Java program is provided below.



Here’s the
code you are to carefully enter into NetBeans, compile and execute:


Note: some of these lines are already provided. Enter the lines not prese
nt on IDE:


/*


* Main.java


*


* Created on June

2
3
, 20
10
,
12:00pm


*


* To change this template, choose Tools | Template Manager


* and open the template in the editor.


*/


package project0whooper;

// enter your project
, such as project0jsmith;


/*
*


*


* @author n00010109




// provided by the IDE


*/

public class Main {





// add code starting at arrow:









// Be certain to indent!


/** Creates a new instance of Main */


public Main() {


}




/**


* @param args the com
mand line arguments


*/


public static void main(String[] args) {


// TODO code application logic here


int sides = 7;




//declaration with initialization


System.out.println ("A heptagon has " + sides + " sides.");





sides = 10;


System.out.println ("A decagon has " + sides + " sides.");




sides = 12;


System.out.println ("A dodecagon has " + sides + " sides.");


}// end main()



}// end class


My screen looks like:




Note t
he very nice coloring: Yellow provides scope bounds; orange indicates string text,
blue indicates key words with special means, and more. These are VERY useful!


To compile and run this application, I clicked on the
green

arrow up in the menu bar.




The output appeared in the Outbox pane. The green arrow requests both compilation and
interpretation/
execution of the code. Yo
u may alternatively use the Menu Bar, Build,
Build Main Project followed by Menu Bar, Run, Run Main Project
, if you wish
.



S
ome quick tips:


1. I went to the View menu and selected Show Line Numbers.

2.
T
hen I went in and mistyped printline on line 25.
NetBeans will often let you know
when you are keying in something it does not recognize even before you attempt to
compile

/ run your program. You can see from the screen below, that as I typed prntln,
NetBeans flagged it immediately. Now, if I persisted and didn’t note that and then tried
to run the project, I would get the output indicated below:





Note that the dia
gnostic indicates the line number where the error was detected. (If you
‘mouse over’ the red ball, the diagnostic text is provided) You will now need to go back
in with your mouse and correct the typo and rerun to get the proper result, which I
indicat
ed in the previous slide.



8
. Submitting the project for grading.



Go to your desktop and open COP
2551
.
If you double click on the project folder, y
ou
will note that there are a number of folders


the same that is reflected in the IDE
windows. You mi
ght find them instructive to open them and ‘look around.’



Zip contents of the folder, project0broggio.

(Right click,
Send

compressed file
T
o

Compressed

Folder
)

The zipped (compressed
icon) should now appear in your COP2551 folder.


You should see






9
. Using Blackboard
Assignment Link
to get Your Assignment
(Project)


Access Blackboard using your n
-
number and your password.


Go to
Course

Documents

in Blackboard.
(
Alternatively, you may access my web page
at
www.unf.edu/~broggio

and select the golden ball next to your course number. All
assignments and help / input files will be available there.
)


You will see the assignment
and all associated files. If you have any questions,

please email me immedi
ately.


Upon completion of your assignments, you must access this Assignment Tab.
This is the
only mechanism for me to receive your assignments. So please be careful.


Within the specific assignment link, you are afforded the opportunity to send me a zip

file
of your work. This zip file should be entitled projectnyouruserid, as in project3broggio
as mentioned previously. This zip file should be located on your desktop in a folder
entitled COP2551 or COP3540 or relevant course number. Be certain the pr
oject folder
is zipped. If you are not familiar with ‘zip’ then please ask.


‘rar’ files are NOT accepted.
If using a
MAC, there
are
special considerations.



Browse

your desktop to identify this zipped folder;
Attach

the zip file using the
appropriate

button to your screen. After you have attached the file, you must then
Submit

the attachment. You will get some information back as to the file size, date,
time, etc. Please hold on to this until I confirm that I have received your zip file and have
s
uccessfully unzipped it.

File Information

(again)
:



Log into Blackboard to access initially and submit your completed assignment.


Browse

your desktop to your COP2551 folder; select
your
zipped

project


file, such as project0
jsmith or whathaveyou
(the

one with the zipper on it)

Attach

the zip file.


Submit
.


In the past, we have had a few difficulties here. If for some reason your zip file is not
received or arrives to me ‘empty,’ and if you have the date/time that you submitted it, I
can have you res
ub
mit with no penalty.


T
o provide yourself with evidence that you have successfully submitted the project, I
recommend that you
go
back into the
A
ssignment on
B
lackboard
(
after uploading

to me)

and download it back to
y
our computer from the server and u
nzip it.

You will see what
you sent to me.

Below is what you will see when clicking on the assignment in
Blackboard again
after

submitting your file. As you can see in the second half of the
page (you may need to zoom), there is a link with the file you

submitted. By clicking on
this, you will download the file that was submitted to be for grading. You may then
unzip this and verify the presence (or absence) of files.



PLEASE ensure you sent to me what you

think


you sent to me.

(See above)

If you

send me the wrong folder, I cannot grade it and you will be hating everyone
including me. Double check your work, please.