TS 69 JavaFX Structures

Revision as of 08:17, 17 May 2010 by Sunflower (Talk | contribs)

Contents


JavaFXReference


Refactoring

class A{
    public var a:A;
    public var name:String;

    public var action:function();

    public function f(){
       
    }

}

mixin class M{
    
}

class B extends A, M{
        override var a = null;
    
}



var a = A{};
var b = B{};



class Point{
    var x:Number;
    var y:Number;
}


class Pin{
    public var position:Point;
}

class ElectronicComponent  {
    var pin1: Pin;
    var pin2: Pin;


    function reset(){
            pin1.position.x = 0;
            pin1.position.y = 0;
    }


}

Formatting

var a   =10.0   ;


function sqr(x:Number) { x * x }

Rectangle{
    transforms: [Rotate{Angle:45},Scale{X:2,Y:0.5} ]
} 

Refactoring

Variables

var a = 10;
var b = a + 20;


Inheritance

class A{

}

class B extends A{

}


Attributes

public class A {

    public var a:Number;

    function f():Number {
        return a;
    }

}


Bind

import javafx.scene.paint.*;
import javafx.scene.shape.*;

Rectangle {
    fill: bind LinearGradient {
        endX: 0
        stops: [
            Stop { offset: 0, color:           Color.BLACK },
            
            Stop { offset: 1,            color: Color.WHITE },
        ]
    }
}

Complex sample

public class A {
    public var attr:String;

    public var a:A;



    public function f(x:Number):Number { x * x}

    public function fa(a:A):A {  var b = a.a; return b; }

}

public function run() {
    var a = A{
          attr: "Hello World!"
    };


    var b = a.fa(a);

    var c= b.f(3);
    
    
    println(a.attr);

}


class Node{
    public var content:String;
    public var head:Node;

    function print(){
        Element(head);
    }

    function Element(elem:Node):Void{
        if(elem != null){
            println(elem);
            Element(elem);
        }
    }
}

Debugger

var a = 10.0;
var b = 20.0;
var c = a + b;


class A{

    var numbers: Number[];
}


var a = A{};

var N = 10;

for(i in [0..<N]){
    insert i into a.numbers;
}

Navigator

var a = 10;
var b = 10.0;
var c = "Hello World";
var f = true;


var seq = [1,2,3];

class A{
    public var aa:Integer;
    var bb:Number;

    function f() {  }
    function f(arg:String) {  }
    function f(args:String[]) {  }
    function f(arg:Integer):Double[[ | ]] { []  }


}



Structures

Package

package a;

public class A {
}


Data Types

var i = 3;
var num = 3.0;

var b = true;

var c = "2".charAt(0);


var byte:Byte = 1;
var short:Short = 2;
var long:Long = 3;
var float:Float = 5.0;
var double:Double = 10.0;


var date = 3h;

var str = "Hello!";

class A{}

var a = A{};

var void = function():Void{};

var f = function(a:Number, b:String):Boolean { true };
var seqf = function(a:A[[ | ]], b:String[[ | ]]):Boolean[[ | ]] { [] };


var seq = ["1","2","3" ];


Sequences

var seq = [1,2,3];

insert 4 into seq;

Classes

class A{}


Attributes

class A{

  public var a:Integer;
}


Function

function sqr(x:Number) { x * x  }

Java Classes

Instantiation

import java.util.Random;

var random  =  new Random(3);

Inheritance

var run  =  java.lang.Runnable{

    override function run(){
        println("run");
    }

}


UI

import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.scene.shape.Circle;
import javafx.scene.paint.Color;


var radius = 10.0;

Stage {
    title: "Application title"
    width: 250
    height: 280
    scene: Scene {
        content: [
            Circle {
                centerX: 100, centerY: 100
                radius: radius
                fill: Color.GOLD
            }

        ]
    }
}


Operators

For


for(a in [1..100]){
    println(a+10);
}

var seq = for(b in [1,5,9]) b + b / 2;
Not logged in. Log in, Register

By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2012, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo