BallongTest.java [Last ned]

/*
 * Programmet tegner en rød ballong med sort tråd.
 */
 
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.Group;
import javafx.scene.paint.Color;
import javafx.scene.shape.Circle;
import javafx.scene.shape.Line;
import javafx.scene.text.Font;
import javafx.scene.text.Text;
import javafx.stage.Stage;
import javafx.application.*;
import javafx.stage.*;
import javafx.scene.*;
 
public class BallongTest extends Application {
 
public static void main(String[] args) {
    launch(args);
  }
 
  public void start(Stage stage) {
    // Definerer vinduet og initierer scenegrafen
    Group root = new Group();
    Scene scene = new Scene(root, 800, 300);
    stage.setScene(scene);
    stage.setTitle("BallongTest");
 
    // Lager selve ballongen
    int x = 100;
    int y = 80;
    int radius = 50;
    Circle ballong = new Circle(x, y, radius);
    ballong.setStroke(Color.BLACK);
    ballong.setFill(Color.RED);
    root.getChildren().add(ballong);
    Line traad = new Line(x, y+radius, x, y+radius*3);
    traad.setStroke(Color.BLACK);
    traad.setFill(Color.BLACK);
    root.getChildren().add(traad);
 
    // Legger til beskrivende tekst
    Font font = new Font("Arial", 44);
    Text txt = new Text(300, 80, "Ballong");
    txt.setFont(font);
    root.getChildren().add(txt);
 
    // Viser scenegrafen
    stage.show();
  }
 
}
Kildekode blir vist ved hjelp av GeSHi.