List of usage examples for javafx.scene Group setTranslateX
public final void setTranslateX(double value)
From source file:Main.java
static Node bloom() { Group g = new Group(); Rectangle r = new Rectangle(); r.setX(10);//from w w w .j a v a 2 s . co m r.setY(10); r.setWidth(160); r.setHeight(80); r.setFill(Color.DARKBLUE); Text t = new Text(); t.setText("Bloom!"); t.setFill(Color.YELLOW); t.setFont(Font.font("null", FontWeight.BOLD, 36)); t.setX(25); t.setY(65); g.setCache(true); //g.setEffect(new Bloom()); Bloom bloom = new Bloom(); bloom.setThreshold(1.0); g.setEffect(bloom); g.getChildren().add(r); g.getChildren().add(t); g.setTranslateX(350); return g; }
From source file:Main.java
static Node displacementMap() { int w = 220;/*www . java 2 s. c om*/ int h = 100; FloatMap map = new FloatMap(); map.setWidth(w); map.setHeight(h); for (int i = 0; i < w; i++) { double v = (Math.sin(i / 50.0 * Math.PI) - 0.5) / 40.0; for (int j = 0; j < h; j++) { map.setSamples(i, j, 0.0f, (float) v); } } Group g = new Group(); DisplacementMap dm = new DisplacementMap(); dm.setMapData(map); Rectangle r = new Rectangle(); r.setX(20.0f); r.setY(20.0f); r.setWidth(w); r.setHeight(h); r.setFill(Color.BLUE); g.getChildren().add(r); Text t = new Text(); t.setX(40.0f); t.setY(80.0f); t.setText("Wavy Text"); t.setFill(Color.YELLOW); t.setFont(Font.font("null", FontWeight.BOLD, 36)); g.getChildren().add(t); g.setEffect(dm); g.setCache(true); g.setTranslateX(400); g.setTranslateY(200); return g; }
From source file:Main.java
@Override public void start(Stage stage) { Group p = new Group(); Scene scene = new Scene(p); stage.setScene(scene);/* ww w . ja v a 2s . c o m*/ stage.setWidth(500); stage.setHeight(500); p.setTranslateX(80); p.setTranslateY(80); //create a circle with effect final Circle circle = new Circle(20, Color.rgb(156, 216, 255)); circle.setEffect(new Lighting()); //create a text inside a circle final Text text = new Text(i.toString()); text.setStroke(Color.BLACK); //create a layout for circle with text inside final StackPane stack = new StackPane(); stack.getChildren().addAll(circle, text); stack.setLayoutX(30); stack.setLayoutY(30); p.getChildren().add(stack); stage.show(); //create a timeline for moving the circle timeline = new Timeline(); timeline.setCycleCount(Timeline.INDEFINITE); timeline.setAutoReverse(true); //You can add a specific action when each frame is started. timer = new AnimationTimer() { @Override public void handle(long l) { text.setText(i.toString()); i++; } }; //create a keyValue with factory: scaling the circle 2times KeyValue keyValueX = new KeyValue(stack.scaleXProperty(), 2); KeyValue keyValueY = new KeyValue(stack.scaleYProperty(), 2); //create a keyFrame, the keyValue is reached at time 2s Duration duration = Duration.millis(2000); //one can add a specific action when the keyframe is reached EventHandler onFinished = new EventHandler<ActionEvent>() { public void handle(ActionEvent t) { stack.setTranslateX(java.lang.Math.random() * 200 - 100); //reset counter i = 0; } }; KeyFrame keyFrame = new KeyFrame(duration, onFinished, keyValueX, keyValueY); //add the keyframe to the timeline timeline.getKeyFrames().add(keyFrame); timeline.play(); timer.start(); }