Run this code and press any key.
import javafx.application.Application;
import javafx.event.EventHandler;
import javafx.scene.Group;
import javafx.scene.PerspectiveCamera;
import javafx.scene.PointLight;
import javafx.scene.Scene;
import javafx.scene.input.KeyEvent;
import javafx.scene.paint.Color;
import javafx.scene.paint.PhongMaterial;
import javafx.scene.shape.Sphere;
import javafx.stage.Stage;
public class PhongMaterialToString extends Application {
PhongMaterial pm;
@Override
public void start(Stage stage) throws Exception {
pm = new PhongMaterial();
pm.setDiffuseColor(Color.LIGHTGRAY);
pm.setSpecularColor(Color.rgb(30, 30, 30));
Sphere sphere = new Sphere();
sphere.setMaterial(pm);
sphere.setScaleX(100);
sphere.setScaleY(100);
sphere.setScaleZ(100);
PointLight pl = new PointLight(Color.RED);
pl.setTranslateZ(-1000);
Group root = new Group(sphere, pl);
root.setTranslateX(250);
root.setTranslateY(250);
Scene scene = new Scene(root, 500, 500, true);
scene.setCamera(new PerspectiveCamera());
scene.setOnKeyPressed(new EventHandler<KeyEvent>() {
@Override
public void handle(KeyEvent t) {
System.out.println(pm.toString());
}
});
stage.setScene(scene);
stage.show();
}
public static void main(String[] args) {
launch(args);
}
}
import javafx.application.Application;
import javafx.event.EventHandler;
import javafx.scene.Group;
import javafx.scene.PerspectiveCamera;
import javafx.scene.PointLight;
import javafx.scene.Scene;
import javafx.scene.input.KeyEvent;
import javafx.scene.paint.Color;
import javafx.scene.paint.PhongMaterial;
import javafx.scene.shape.Sphere;
import javafx.stage.Stage;
public class PhongMaterialToString extends Application {
PhongMaterial pm;
@Override
public void start(Stage stage) throws Exception {
pm = new PhongMaterial();
pm.setDiffuseColor(Color.LIGHTGRAY);
pm.setSpecularColor(Color.rgb(30, 30, 30));
Sphere sphere = new Sphere();
sphere.setMaterial(pm);
sphere.setScaleX(100);
sphere.setScaleY(100);
sphere.setScaleZ(100);
PointLight pl = new PointLight(Color.RED);
pl.setTranslateZ(-1000);
Group root = new Group(sphere, pl);
root.setTranslateX(250);
root.setTranslateY(250);
Scene scene = new Scene(root, 500, 500, true);
scene.setCamera(new PerspectiveCamera());
scene.setOnKeyPressed(new EventHandler<KeyEvent>() {
@Override
public void handle(KeyEvent t) {
System.out.println(pm.toString());
}
});
stage.setScene(scene);
stage.show();
}
public static void main(String[] args) {
launch(args);
}
}
- duplicates
-
JDK-8124241 PhongMaterial.toString() method produces StackOverflowError
- Closed