package javafx_reflection; import javafx.application.Application; import javafx.beans.value.ObservableValue; import javafx.event.ActionEvent; import javafx.geometry.Insets; import javafx.scene.Group; import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.control.Label; import javafx.scene.control.Slider; import javafx.scene.effect.Reflection; import javafx.scene.image.Image; import javafx.scene.image.ImageView; import javafx.scene.layout.VBox; import javafx.scene.paint.Color; import javafx.scene.text.Font; import javafx.scene.text.Text; import javafx.stage.Stage; /** * * @web http://java-buddy.blogspot.com/ */ public class JavaFX_Reflection extends Application { @Override public void start(Stage primaryStage) { primaryStage.setTitle("java-buddy.blogspot.com"); Group root = new Group(); Scene scene = new Scene(root, 700, 600, Color.WHITE); Reflection reflection = new Reflection(); Button btn = new Button("Click Me"); btn.setOnAction((ActionEvent event) -> { if(btn.getText().equals("Click Me")){ btn.setText("Hello! Thanks..."); reflection.setBottomOpacity(1.0); }else{ btn.setText("Click Me"); reflection.setBottomOpacity(0.0); } }); btn.setEffect(reflection); Text textView = new Text(50, 150, "java-buddy.blogspot.com"); textView.setFill(Color.BLUE); textView.setFont(Font.font("Monospaced", 40)); textView.setEffect(reflection); ImageView imageView = new ImageView(new Image("http://goo.gl/kYEQl")); imageView.setEffect(reflection); Slider slider = new Slider(); slider.setMin(-50); slider.setMax(250); slider.setValue(0); slider.valueProperty().addListener( (ObservableValue<? extends Number> ov, Number old_val, Number new_val) -> { reflection.setTopOffset((double) new_val); }); Label labelInfo = new Label(); labelInfo.setText( "java.version: " + System.getProperty("java.version") + "\n" + "javafx.runtime.version: " + System.getProperty("javafx.runtime.version") + "\n" + "os.name: " + System.getProperty("os.name") ); labelInfo.setEffect(reflection); VBox vBox = new VBox(); vBox.setPadding(new Insets(20, 20, 20, 20)); vBox.getChildren().addAll(labelInfo, imageView, textView, btn, slider); root.getChildren().add(vBox); primaryStage.setScene(scene); primaryStage.show(); } public static void main(String[] args) { launch(args); } }
Next: JavaFX Transition Animation with Reflection effect
No comments:
Post a Comment