/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package helloworld; import com.sun.javafx.perf.PerformanceTracker; import javafx.animation.KeyFrame; import javafx.animation.KeyValue; import javafx.animation.Timeline; import javafx.application.Application; import javafx.application.Launcher; import javafx.collections.ObservableList; import javafx.event.ActionEvent; import javafx.event.EventHandler; import javafx.scene.*; import javafx.scene.control.*; import javafx.stage.Stage; import javafx.scene.paint.Color; import javafx.scene.paint.CycleMethod; import javafx.scene.paint.LinearGradient; import javafx.scene.paint.Stop; import javafx.scene.shape.Rectangle; import javafx.scene.text.Font; import javafx.scene.text.Text; import javafx.util.Duration; public class GradientSwitchingtest extends Application { private static final Stop[] stops1 = new Stop[]{new Stop(0, Color.BLACK), new Stop(1, Color.RED)}; private static final Stop[] stops2 = new Stop[]{new Stop(0, Color.BLACK), new Stop(1, Color.GREEN)}; @Override public void start(Stage stage) { stage.setTitle("Hello CheckBox"); stage.setWidth(100); stage.setHeight(200); final Group vbox = new Group(); final Scene scene = new Scene(vbox); final Rectangle rect = new Rectangle(); rect.setX(25); rect.setY(40); rect.setWidth(100); rect.setHeight(50); rect.setFill(Color.RED); ((Group)scene.getRoot()).getChildren().add(rect); stage.setScene(scene); stage.setVisible(true); final Timeline timeline = new Timeline(); timeline.setCycleCount(Timeline.INDEFINITE); timeline.setAutoReverse(true); final KeyValue kv = KeyValue.keyValue(rect.xProperty(), 100); final KeyFrame kf = new KeyFrame(Duration.valueOf(1000), kv); timeline.getKeyFrames().add(kf); timeline.play(); //VBox vbox = new VBox(); //vbox.setSpacing(10); // for (int i=0; i<3; i++) { // CheckBox cb = new CheckBox((new Integer(i)).toString()); // cb.setSelected(true); // cb.setLayoutY(i*25); // vbox.getChildren().add(cb); // } boolean toggle = true; for (int i=0; i<4000; i++) { Rectangle node = new Rectangle(); node.setWidth(60); node.setHeight(20); if(toggle) { node.setFill(new LinearGradient(0.0f, 0.0f, 1.0f, 0.0f, true, CycleMethod.NO_CYCLE, stops1)); toggle = false; } else { node.setFill(new LinearGradient(0.0f, 0.0f, 1.0f, 0.0f, true, CycleMethod.NO_CYCLE, stops2)); toggle = true; } node.setLayoutY(80+i*25); vbox.getChildren().add(node); } ObservableList content = ((Group)scene.getRoot()).getChildren(); //content.add(vbox); final Text text = new Text("??? fps"); text.setFont(new Font(12)); text.setLayoutX(50); text.setLayoutY(45); content.add(text); final PerformanceTracker tracker = PerformanceTracker.getSceneTracker(scene); final Timeline tlTracker = new Timeline(); tlTracker.setCycleCount(Timeline.INDEFINITE); final KeyFrame kfTracker = new KeyFrame( Duration.valueOf(500), new EventHandler() { public void handle(ActionEvent event){ int fps = (int) Math.round(tracker.getInstantFPS()); text.setContent("" + fps + " fps"); text.setFill(text.getFill().equals(Color.BLACK)?Color.BLUE:Color.BLACK); System.err.println("FPS:" + fps); } }); tlTracker.getKeyFrames().add(kfTracker); tlTracker.play(); stage.setScene(scene); stage.setVisible(true); } private static Scene newScene() { Scene scene = new Scene(new Group()); return scene; } public static void main(String[] args) { Launcher.launch(GradientSwitchingtest.class, args); } }