Top Banner
From BlueJ to NetBeans SWC 2.semester
42

From BlueJ to NetBeans

Feb 12, 2016

Download

Documents

zihna

From BlueJ to NetBeans. SWC 2.semester. Why change…?. BlueJ is great for introduction to programming Simple interface, few options Graphical interface to classes and objects Some tehnical details are hidden. Why change…?. NetBeans is great for professional programming - PowerPoint PPT Presentation
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: From BlueJ to NetBeans

From BlueJ to NetBeansSWC 2.semester

Page 2: From BlueJ to NetBeans

Why change…?BlueJ is great for introduction to

programming◦Simple interface, few options◦Graphical interface to classes and

objects◦Some tehnical details are hidden

Page 3: From BlueJ to NetBeans

Why change…?NetBeans is great for professional

programming◦Much more functionality◦Better editor, debugger,…◦Integration to database systems◦A full-blown, stand-alone system

…but also more complex!

Page 4: From BlueJ to NetBeans

What is NetBeans?NetBeans is an open-source

projectOriginates from SUN

Microsystemswww.netbeans.orgCan - of course – be downloaded

for free from the websiteWe use NetBeans 6.9.1 SE (+

Java JDK)

Page 5: From BlueJ to NetBeans

What is NetBeans?

Page 6: From BlueJ to NetBeans

How do I……create a new project?…add a new class?…edit a class definition?…write text to the screen?…get input from the user?…run a project?

Page 7: From BlueJ to NetBeans

Create a new project - BlueJ

Choose Project | New Project…

Page 8: From BlueJ to NetBeans

Create a new project - BlueJ

Enter project name, press ”Create”

Page 9: From BlueJ to NetBeans

Create a new project - NetBeans

Choose File | New Project…

Page 10: From BlueJ to NetBeans

Create a new project - NetBeans

In Categories, choose ”Java”

In Projects, choose ”Java Application”

Page 11: From BlueJ to NetBeans

Create a new project - NetBeans

Enter project name and location

Page 12: From BlueJ to NetBeans

Create a new project - NetBeans

Page 13: From BlueJ to NetBeans

Create a new project - NetBeansWhy is there a ”Main.java”

class…?All Java programs must contain a

method with this signature:public static void main(String[] args)

This was hidden in BlueJ!Think of Main as a ”System”

classWhen the program starts, the

code in the main(…) method is executed

Page 14: From BlueJ to NetBeans

Add a new class- BlueJPress ”New Class…”

Enter class name

Page 15: From BlueJ to NetBeans

Add a new class- BlueJ

Page 16: From BlueJ to NetBeans

Add a new class- NetBeans Highlight

the bankaccount package!

Choose New | Java Class

Page 17: From BlueJ to NetBeans

Add a new class- NetBeans

Enter class name

Page 18: From BlueJ to NetBeans

Add a new class- NetBeans

Page 19: From BlueJ to NetBeans

Edit a class definition - BlueJ

Double-click on the class icon

Page 20: From BlueJ to NetBeans

Edit a class definition - BlueJ

Page 21: From BlueJ to NetBeans

Edit a class definition - NetBeans

Double-click on the class icon

Page 22: From BlueJ to NetBeans

Edit a class definition - NetBeans

Note the file panes in NetBeans

Page 23: From BlueJ to NetBeans

Edit a class definition - NetBeansWhy do red lines start to appear

in the code, as soon as I start typing…?

The NetBeans editor continuously makes an analysis of the code, even before it is compiled

The editor highlights errors in the code by a waved red line, even before typing has been completed

Helpful…? Annoying…?

Page 24: From BlueJ to NetBeans

Edit a class definition - NetBeans

Yes, I know, but I am still typing!!

Page 25: From BlueJ to NetBeans

Edit a class definition - NetBeans

See hints by hovering mouse over (!)

Page 26: From BlueJ to NetBeans

Edit a class definition - NetBeansWhy do lists with method names

pop up when I type…?The NetBeans editor supports

”auto-completion”, i.e. it tries to predict what you will type next

Typically when calling a method with ”.”

Helpful, when you get used to it…

Page 27: From BlueJ to NetBeans

Edit a class definition - NetBeans

Available methods on the specific object/class

Documentation for each method

Page 28: From BlueJ to NetBeans

Writing text to the screen - BlueJ

Page 29: From BlueJ to NetBeans

Writing text to the screen - BlueJ

Page 30: From BlueJ to NetBeans

Writing text to the screen - NetBeans

Page 31: From BlueJ to NetBeans

Writing text to the screen - NetBeans

Need this code for actually executing the method

Page 32: From BlueJ to NetBeans

Writing text to the screen - NetBeans

Output written to the ”Output window”

Page 33: From BlueJ to NetBeans

Get input from the user - BlueJ

Page 34: From BlueJ to NetBeans

Get input from the user - BlueJ

Enter parameter value directly

Page 35: From BlueJ to NetBeans

Get input from the user - NetBeansNot quite as simple to get input

from a user in NetBeansTwo options

◦Use the Scanner class◦Use a input dialog class

See chapter 3.6 in Big Java for details

Page 36: From BlueJ to NetBeans

Get input from the user - NetBeansimport java.util.Scanner;…Scanner in = new Scanner(System.in);…String name = in.nextLine();…int balance = in.nextInt();…double area = in.nextDouble();

Page 37: From BlueJ to NetBeans

Get input from the user - NetBeansimport javax.swing.JOptionPane;…String value = JOptionPane.showInputDialog(”Limit”);

…int limit = Int.parseInt(value);

Page 38: From BlueJ to NetBeans

Running a project - BlueJWe cannot as such ”run” a

project in BlueJ – what should run..?

We usually create a ”system” class, that has a ”run”-like method◦Create a System object◦Right-click the object◦Call the run method

Page 39: From BlueJ to NetBeans

Running a project - NetBeans

Choose Run | Run Main Project

Page 40: From BlueJ to NetBeans

Running a project - NetBeans

…or just click the green triangle (or press F6)

Page 41: From BlueJ to NetBeans

Running a project - NetBeansRunning a project always

executes the main method in the Main class!

A project is automatically compiled when you save it

No reason to run a project in order to fix syntax errors

Page 42: From BlueJ to NetBeans

Other NetBeans featuresA GUI Builder – build a GUI by

drag-drop of controls. Code is auto-generated

A much more powerful debuggerMore customisableEasy integration to database

systemsWe will talk about additional

features later on…