The Cutting Edge Tech Blog


NetBean by FSherratt

NETBEAN Febuary 28 2009

Ever wanted to make one of those amazing java applications? Don’t have any money to spend learning? well i may just have the solution. Netbeans is a free application designed specifically for writing java/C++. This article should help you write your first piece of Java code and soon you’ll be on your way to writing a full application.

First you’ll need to download and install Netbeans. You can downlaod it here. Then boot it up.

java-fx-picture-1

And wait for it to load.

java-fx-picture-2

Then create a New Project

java-fx-picture-4

Select JavaFX and then JavaFX Script Application.

java-fx-picture-5

Name it Calculator and deselect Create Main File.

java-fx-picture-6

Next create a New File.

java-fx-picture-8

Select JavaFx and then Empty JavaFx File

java-fx-picture-9

Name this Calculator and press Finish

java-fx-picture-10

Delete all the code that appears.

java-fx-picture-11

Then paste this code in:

def numOne = 100;
def numTwo = 2;
var result;

add();
subtract();
multiply();
divide();

function add() {
    result = numOne + numTwo;
    println("{numOne} + {numTwo} = {result}");
}

function subtract() {
    result = numOne - numTwo;
    println("{numOne} - {numTwo} = {result}");
}

function multiply() {
    result = numOne * numTwo;
    println("{numOne} * {numTwo} = {result}");
}

function divide() {
    result = numOne / numTwo;
    println("{numOne} / {numTwo} = {result}");
}

Next press the run button and watch your results appear.

javafx-picture-12

I shall now attempt to explain how this works. Right here goes.

def numOne = 100;
def numTwo = 2;
var result;

The first three line of code tell the computer what the variables are.
def variables stay constant and never change. So if you enter numOne it will always be 100
var variables change to make the function
so the line

println("{numOne} * {numTwo} = {result}");

will always equal 100 x 2 = 200

The next three line of code

add();
subtract();
multiply();
divide();

These can be placed anywhere in the script. These tell the computer where to place the information generated from the function carried out.

Final the next four groups of code

function add() {
    result = numOne + numTwo;
    println("{numOne} + {numTwo} = {result}");
}

function subtract() {
    result = numOne - numTwo;
    println("{numOne} - {numTwo} = {result}");
}

function multiply() {
    result = numOne * numTwo;
    println("{numOne} * {numTwo} = {result}");
}function divide() {
    result = numOne / numTwo;
    println("{numOne} / {numTwo} = {result}");
}

These are the actual functions. Take

function add() {
    result = numOne + numTwo;
    println("{numOne} + {numTwo} = {result}");
}

for example. This tell the computer that numOne or 100 needs to be added to numTwo or 2.

println("{numOne} + {numTwo} = {result}");

It then tells the computer that this will equal result and that this needs to to displayed.

result = numOne + numTwo;

This is some very basic script. If you want to improve your knowledge of Java then JavaFX.com is probably the best place to start.

If you’ve enjoyed this article or something to add why not leave a comment.

Add to Technorati Favorites Paypal

Advertisements

Leave a Comment so far
Leave a comment



Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s



%d bloggers like this: