/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package test; import javafx.application.Application; import javafx.event.EventHandler; import javafx.scene.Group; import javafx.scene.LightBase; import javafx.scene.PerspectiveCamera; import javafx.scene.PointLight; import javafx.scene.Scene; import javafx.scene.input.KeyEvent; import javafx.scene.shape.Sphere; import javafx.stage.Stage; /** * * @author Andrew Glushchenko */ public class LightScopeTestApp extends Application { private static int WIDTH = 500; private static int HEIGHT = 500; private Group root; @Override public void start(Stage stage) { root = new Group(); root.setTranslateX(WIDTH / 2); root.setTranslateY(HEIGHT / 2); root.getChildren().add(new Group(new Sphere(50))); Scene scene = new Scene(root, WIDTH, HEIGHT, true); scene.setCamera(new PerspectiveCamera()); scene.setOnKeyPressed(new EventHandler() { @Override public void handle(KeyEvent t) { switch (t.getText()) { case "+": buildNewLight().translateXProperty().set(240); break; } } }); stage.setScene(scene); stage.show(); } private VisibleLight buildNewLight() { VisibleLight newLight = new VisibleLight(); root.getChildren().add(newLight); return newLight; } public static void main(String[] args) { launch(args); } private class VisibleLight extends Group { private LightBase lightBase; public VisibleLight() { lightBase = new PointLight(); Sphere light = new Sphere(50); this.getChildren().addAll(lightBase, light); } } }