Working with JavaFX Classes and Objects |
|
Here we will have a look over some programming facts before going to develop our JavaFX script
applications. This will help you understand how the JavaFX script programming works.
i) Scripts:
In JavaFX script programming language, a script doesn’t require any class or function. You can use
one or more declarations or expressions that are evaluated and produce output.
For example, the script below:
var firstdigit : Integer = 10;
var seconddigit : Integer = 20;
var sum : Integer = firstdigit + seconddigit;
java.lang.System.out.println(“Sum of {firstdigit} and {seconddigit} is {sum}.”);
Produces output as:
Sum of 10 and 20 is 30.
ii) Classes and objects:
1. Importing Classes:
Importing packages and classes is like the way we do while programming with java.
import MyPackage1.*;
import MyPackage2.MyClass;
In JavaFX Script programming language, standard java programming language packages and classes
can also be imported along with its built-in packages and classes.
For example:
import javafx.animation.*;
import javafx.scene.image.Image;
import java.lang.System;
2. Defining Classes:
The class in JavaFX can be defined with ‘class’ keyword. The ‘extends’ keyword can be used for
inheritance purpose. JavaFX supports multiple inheritance so you can list the name of base classes
separated with comma after the ‘extends’ keyword.
For example:
public class AnimatedImage extends ImageView {
……………………….
……………………….
private attribute imagesCount: Integer = 0;
private attribute images: Image[];
private attribute currentImageIndex:Integer ; |
|
Aug 2008 | Java Jazz Up | 19 |
|
|
|
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 |
|
|
|