Java Reference
In-Depth Information
The default constructor creates a PointLight with a default color of Color.WHITE . The one-parameter
constructor creates a PointLight with the specified color. The PointLight class has no additional public methods
aside from the ones it inherited from the LightBase class.
The program in Listing 10-6 illustrates the use of lights in a JavaFX 3D scene. Two PointLight s, one red and one
blue, are added to a scene that already has a Box and a PerspectiveCamera . A control panel with sliders that can alter
the coordinates of the two lights is added at the bottom of the window to allow you to see the effect of the lights being
located at various locations.
Listing 10-6. LightExample.java
import javafx.application.Application;
import javafx.beans.property.DoubleProperty;
import javafx.beans.property.SimpleDoubleProperty;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.*;
import javafx.scene.control.Label;
import javafx.scene.control.Slider;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.scene.paint.Color;
import javafx.scene.shape.Box;
import javafx.scene.transform.Rotate;
import javafx.scene.transform.Translate;
import javafx.stage.Stage;
public class LightExample extends Application {
private Model model;
private View view;
public LightExample() {
model = new Model();
}
@Override
public void start(Stage stage) throws Exception {
view = new View(model);
stage.setTitle("Light Example");
stage.setScene(view.scene);
stage.show();
}
public static void main(String[] args) {
launch(args);
}
private static class Model {
private DoubleProperty redLightX = new SimpleDoubleProperty(this, "redLightX", 20.0d);
private DoubleProperty redLightY = new SimpleDoubleProperty(this, "redLightY", -15.0d);
private DoubleProperty redLightZ = new SimpleDoubleProperty(this, "redLightZ", -20.0d);
private DoubleProperty blueLightX = new SimpleDoubleProperty(this, "blueLightX", 15.0d);
Search WWH ::




Custom Search