Week 1 - Netbeans IDE
Week 1 - Netbeans IDE
Provides
an environment where tools needed for source code editing, compiling, testing, debugging are seamlessly integrated.
Write and edit source code See errors as you type See highlighted code syntax Compile code Browse class structures Use drag-and-drop utilities for easy building of features, such as graphic objects or creating database connections
Automatically create classes, methods, and properties Provide code-completion as you type Integrate with web application servers, such as Apache Tomcat
developing applications it saves you time by managing windows, settings and data. Drag-and-drop features make creating GUI components or accessing databases easy Highlighted code and debugging features alert you to errors in your code moving from one phase of code development to the other is very simple. User need not be bothered about the tool interfaces Many people learn to program using a simple text editor, but most of them end up using an integrated development environment (IDE) for building applications !
NetBeans (open-source)
Sun Java Studio Creator Sun Java Studio Enterprise. Eclipse (open-source) Visual Age for Java
IBM supports:
Borland
supports:
JBuilder
is open source (free for commercial and noncommercial use) and is supported by Sun Microsystems. source => continual improvement => slight differences between various versions enables developers to rapidly create
web, enterprise, desktop, and mobile applications using the Java platform, PHP, JavaScript and Ajax, Ruby and Ruby on Rails, Groovy, and C/C++.
open It
Provides Provides
the services common to desktop applications such as window and menu management, settings storage, etc. tools for:
Source Code Editor, GUI Builder, Database support
Download a stable version (Version 6.9 or 7 ) from the NetBeans web site : NetBeans IDE with JDK Bundle
Install the NetBeans kit Start the application => You will notice the welcome screen
Choose Tools > Java Platform manager. Select Javadoc. In the Javadoc tab, click Add ZIP/Folder and specify the location of the Javadoc files.
an organized group of source files and associated metadata; project-specific properties files; all the tools you'll need to write, compile, test, and debug your application.
want to develop a simple application that prints the message Hello world!
Hello class that has only the main() method - prints the message
field: hello.HelloMessage
Finish button
10
11
Projects Main 2.
windows -> Source Pakages: all pakages and java files developed under this project steps: Start to edit your source code
we already have HelloMessage class, but we need to write code in the main() method and other methods that we want to develop. System.out.println(Hello World);
12
13
14
that you have built the project, you can run your program steps:
4. Running
the program
in the Output Windows
15
application may need to be extended with other Java classes or files steps: new Java classes to your project
5. Add/Write
Main
File=>New File=> Java Class as class types => press Next button Set Class Name: Person, then press Finish button
16
17
18
Atributes:
public
Constructor:
Person
Methods:
public String getName() public void setName(String inName)
public
20
We
Use the GUI Builder Interface Create a Java application with a GUI Add and resize graphical components (e.g Buttons, Labels) Edit graphical component properties Add functionality to the grapical component properties (e.g. button click)
21
Create
a GUI Container
To proceed with building our interface, we need to create a Java container within which we will place the other required GUI components (e.g. Buttons, Labels)
22
23
Set
Enter guiapp as
Package Name
24
25
Palette
Project
Design Area Properties
Inspector
26
Design Area
The GUI Builder's primary window for creating and editing Java GUI forms. The toolbar's Source and Design toggle buttons enable you to view a class's source code or a graphical view of GUI Form. Provides a representation of all the components, both visual and non-visual, in your application as a tree hierarchy. A customizable list of available components part of JFC/Swing, AWT and JavaBeans components, as well as layout managers Displays the properties of the component currently selected in the GUI Builder, Inspector window, Projects window, or Files window.
Inspector
Palette
Properties Window
27
28
Often helpful to sketch out the way you want your interface to look before beginning to lay it out. Adding JPanel
we've already added a JFrame as our form's top-level container, next step is to add a couple of JPanels which will enable us to cluster the components of our GUI using titled borders . In the Palette window, select the Panel component from the Swing Containers category Move the cursor to the upper left corner of the Design Area Resize the JPanel:
Select the JPanel you just added Click and hold the resize handle on the right edge of the JPanel and drag
Properties Window.
Add 2 JPanels in the Design area of your project Add title borders to the JPanels
Select the top JPanel element added, then in the Properties window, click next to Border property Select TitleBorder and then, fill in the Title as: Persons Details
29
Individual Components to the Form that will present information related to a person
Name => we need a JLabel and JTextField
Add
In the Palette window, select the JLabel component from the Swing Controls category Move the cursor over the Persons Details JPanel we added earlier and click to place the label Edit the display text of the JLabel: Double-click the added JLabel and type in Name.
Add
In the Palette window, select the JTextField component from the Swing category Move the cursor immediately to the right of the Name JLabel and click
30
In the Palette window, select the JButton component Move the JButton in the lower JPanel (Display Info), right corner Double-click on the JButton and enter the text for its name.
Add
Add 2 buttons to the Display Info Panel named: List and Exit Add a JTextArea to the form
In the Palette window, select the JTextArea component from the Swing category
Move the cursor to the left top corner of the Display Info Panel Resize the JTextArea
31
that you have successfully built the GUI, you can try your interface to see the results
clicking the Preview Form button in the GUI Builder's toolbar.
The
form opens in its own window, allowing you to test it prior to building and running.
32
We are going to give functionality to the Add, List and Exit buttons To give a function to a button, we have to assign an event handler
We are now going to add code for what we want the Exit Button to do
System.exit(0);
Note that the Events --> Action --> menu contains more events you can respond to!
33
Right Click on the Add button. From the pop-up menu choose Events --> Action --> ActionPerformed. IDE automatically adds an ActionListener to the Add button and opens up the Source Code window We are going to take user input from jTextField1 variable and display the string in jTextArea1 variable assigned to the GUI component. Code for jButton1ActionPerformed() method
String name; name = jTextField1.getText(); jTextArea1.append("Person name is:"+ name+\n);
34
35
36
Learning Outcome
What is IDE? Some examples of IDE for Java platform NetBeans IDE Main characteristics How to create, develop, compile, debug and run a simple java application developed in NetBeans How to develop GUI for a NetBeans project