Magazine
 
Quick Review:JavaFX
 
Working with JavaFX Classes and Objects
 

……………………….
……………………….
public function play():Void {
if (images == null) {
loadImages();
}
movieTimeline.start();
}
public function stop():Void {
movieTimeline.stop();
}
………………………
………………………
}

3. Creating Objects:

There are two ways to instantiate the class: Using object literal and the traditional way i.e. using ‘new’ keyword. Object literal should be preferred for creating object. For this, write the name of the class followed by pair of curly braces and then inside of the braces give values to the attributes of the class.

For example:

class MyClass {
attribute firstvalue: Integer;
attribute secondvalue: Integer;
function add(value1: Integer, value2: Integer): Integer {
return value1 + value2;
}
}
//Create object of MyClass
var obj = MyClass{
firstvalue : 10
secondvalue : 20
}
var a = obj.firstvalue + 5;
var b = obj.secondvalue + 5;
java.lang.System.out.println(“Sum is: “+ obj.add(a,b));

The output of the above program will be as below:

Sum is: 40

iii) Attributes and Functions:

1. Attributes:

Attributes represent the states of the object. Attributes are declared using ‘attribute’ keyword as given below:

Aug 2008 | Java Jazz Up | 20
 
previous
index
next
 
 
Pages: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29,

30
, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57,

58, 59, 60, 61, 62, 63 Download PDF