netbeans ide - uml modelling
Post on 17-Jul-2016
23 Views
Preview:
DESCRIPTION
TRANSCRIPT
1
UML Modelling
with NetBeans IDE
Mark Burleigh
January 2010
2
Table of Contents
1.1 Creating a new Java Application project............................................................................ 4
1.2 Creating a New UML Application Project ......................................................................... 6
1.3 Creating a New Java Class ................................................................................................. 8
1.4 Creating a Class Attribute .................................................................................................. 9
1.5 Creating an Association between Classes ........................................................................ 12
1.6 Generating Java Code from UML Class Diagram ........................................................... 14
1.7 Index ................................................................................................................................. 16
Table of Figures
Figure 1.1: Open Netbeans IDE.....................................................................................................4
Figure 1.2: Choose Project Type ...................................................................................................4
Figure 1.3: Choose Project Name ..................................................................................................5
Figure 1.4: Create a UML Project..................................................................................................6
Figure 1.5: Select UML Category..................................................................................................6
Figure 1.6: UML Project Location.................................................................................................7
Figure 1.7: Select UML Diagram Type .........................................................................................7
Figure 1.8: UML Pane and Pallette................................................................................................8
Figure 1.9: Create UML Class .......................................................................................................8
Figure 1.10: Change UML Class Name.........................................................................................9
Figure 1.11: Create a Class Attribute.............................................................................................9
Figure 1.12: Maximise UML Window Pane................................................................................11
Figure 1.13: Edit Prefix Name of Attributes and Methods..........................................................12
Figure 1.14: Create UML Class Association ...............................................................................12
Figure 1.15: Generate Code from UML ......................................................................................14
Figure 1.16: Select Target Folder to Save Generated Code.........................................................14
Figure 1.17: View Generated Source Code .................................................................................15
3
Figure 1.18: Generated Source Code ...........................................................................................15
UML Modelling with Netbeans IDE
4
1.1 Creating a new Java Application project
Firstly, we need to create a project for the Java source code that will get generated by your
UML Modelling.
Launch Netbeans IDE from the Start | All Programs menu. Then click on the New Project
button as depicted in Figure 1.1 below or go to File | New Project.
Figure 1.1: Open Netbeans IDE
In the Categories Section, select Java Folder. In the Projects Section select Java Application
as shown below in Figure 1.2
Figure 1.2: Choose Project Type
UML Modelling with Netbeans IDE
5
Next, create a project for the generated Java code. Name the project UML_SRC_CODE and
select the Project location in a new folder in your home directory. Name the new folder as
UML_SRC_CODE.
Figure 1.3: Choose Project Name
When have successfully created your new UML_SRC_CODE project you will see the
following screen shot below. There will be one difference between your screen and the screen
below and that is the background colour of the editor pane. Yours will be white and mine is
black.
Note: For the consummate developer, a black background editor screen has been found to be
more soothing on the eyes. If you wish to change the background colour of your editor, click
the cursor inside you editor pane and then go to Tools | Options | Font & Colors. For each
Category select background colour as black. This can be quite tedious and time consuming so
be warned.
UML Modelling with Netbeans IDE
6
1.2 Creating a New UML Application Project
Now we create a completely new project for the UML class diagrams. Click on the New Project
button as pointed out in the figure below.
Figure 1.4: Create a UML Project
In the Categories section, select the UML folder and in the Projects section, select Java
Platform Model as depicted below.
Figure 1.5: Select UML Category
UML Modelling with Netbeans IDE
7
Name the project UML_PROJECT and save in a folder called UML_PROJECT
Figure 1.6: UML Project Location
In the Diagram Type, select Class Diagram and click Finish.
Figure 1.7: Select UML Diagram Type
UML Modelling with Netbeans IDE
8
You should now have the following screen as shown below.
Figure 1.8: UML Pane and Pallette
1.3 Creating a New Java Class
In the Palette, click on the Class and left click the mouse in the white box. Then right click the
mouse anywhere in the white box area to prevent further UML class diagrams from being
created.
Note: if you wish to create several classes, just keep left clicking and then right click the mouse
to stop generating Classes.
Figure 1.9: Create UML Class
UML Modelling with Netbeans IDE
9
Change the name of the UML class name to Student by double clicking on Unnamed. Notice
that the method inside the class body gets changed too. This is the Constructor of the class.
Figure 1.10: Change UML Class Name
1.4 Creating a Class Attribute
Move the cursor over the Attribute word in the class diagram and right click the mouse then
select Insert Attribute.
Figure 1.11: Create a Class Attribute
UML Modelling with Netbeans IDE
10
Change the attribute from Unnamed to student_num and then press the return (enter) on the
keyboard.
Note: Coding convention is that all classes begin with a capital letter and all attributes and
methods begin in lower case.
When you create an attribute, two methods (operations) get automatically created for that
particular attribute, that is, getStudent_num() and setStudent_num(int val)
UML Modelling with Netbeans IDE
11
Create a second class diagram called Module and insert a new attribute called module_name of
type String.
Maximise the UML diagram window and close the output panel underneath:
Figure 1.12: Maximise UML Window Pane
Click tools | options |Java Code Generation tab | Prefix for member attributes and type
instance_
UML Modelling with Netbeans IDE
12
Figure 1.13: Edit Prefix Name of Attributes and Methods
1.5 Creating an Association between Classes
Now create an Association between Student and Module classes. Click on Navigable
association as pointed out below.
Figure 1.14: Create UML Class Association
Then Click on Student Class and drag the association to the Modules class followed by right
clicking anywhere in the white box area to prevent further associations from being created.
UML Modelling with Netbeans IDE
13
As you can see below, a Student class is comprised of a Module class.
UML Modelling with Netbeans IDE
14
1.6 Generating Java Code from UML Class Diagram
Click on the Student and then right click. Then select Generate Code as shown below. Do the
same for the Module Class.
Figure 1.15: Generate Code from UML
Select the Target Project as the UML_SRC_CODE project (The project that created earlier).
All source code will generated and stored in that project. Go to the UML_SRC_CODE folder
and find the src folder. This is where the generated code is saved.
Figure 1.16: Select Target Folder to Save Generated Code
UML Modelling with Netbeans IDE
15
Right click the Student Class and select Navigate to Source.
Figure 1.17: View Generated Source Code
The source code of the Student Class is shown.
Figure 1.18: Generated Source Code
Index
16
1.7 Index
Association............................................... 12
Attribute.................................................... 9
Categories .............................................. 4, 6
Class ................................ 7, 8, 9, 12, 14, 15
Generate Code ........................................ 14
IDE............................................................. 1
Insert Attribute ........................................ 9
Java .................................... 4, 5, 6, 8, 11, 14
Java Application .........................................4
Maximise ..................................................11
Navigate to Source ..................................15
NetBeans.....................................................1
Palette.........................................................8
source code .....................................4, 14, 15
UML..................1, 4, 5, 6, 7, 8, 9, 11, 12, 14
UML Modelling......................................1, 4
top related