List of usage examples for javafx.animation KeyFrame KeyFrame
public KeyFrame(@NamedArg("time") Duration time, @NamedArg("values") KeyValue... values)
From source file:Main.java
@Override public void start(Stage stage) { Text msg = new Text("java2s.com"); msg.setTextOrigin(VPos.TOP);/*from www. ja v a 2s . c om*/ msg.setFont(Font.font(24)); Pane root = new Pane(msg); root.setPrefSize(500, 70); Scene scene = new Scene(root); stage.setScene(scene); stage.setTitle("Scrolling Text"); stage.show(); double sceneWidth = scene.getWidth(); double msgWidth = msg.getLayoutBounds().getWidth(); KeyValue initKeyValue = new KeyValue(msg.translateXProperty(), sceneWidth); KeyFrame initFrame = new KeyFrame(Duration.ZERO, initKeyValue); KeyValue endKeyValue = new KeyValue(msg.translateXProperty(), -1.0 * msgWidth); KeyFrame endFrame = new KeyFrame(Duration.seconds(3), endKeyValue); Timeline timeline = new Timeline(initFrame, endFrame); timeline.setCycleCount(Timeline.INDEFINITE); timeline.play(); }
From source file:Main.java
private void addBouncyBall(final Scene scene) { final Circle ball = new Circle(100, 100, 20); final Group root = (Group) scene.getRoot(); root.getChildren().add(ball);/* w w w .j a v a2 s . c o m*/ Timeline tl = new Timeline(); tl.setCycleCount(Animation.INDEFINITE); KeyFrame moveBall = new KeyFrame(Duration.seconds(.0200), new EventHandler<ActionEvent>() { public void handle(ActionEvent event) { double xMin = ball.getBoundsInParent().getMinX(); double yMin = ball.getBoundsInParent().getMinY(); double xMax = ball.getBoundsInParent().getMaxX(); double yMax = ball.getBoundsInParent().getMaxY(); if (xMin < 0 || xMax > scene.getWidth()) { dx = dx * -1; } if (yMin < 0 || yMax > scene.getHeight()) { dy = dy * -1; } ball.setTranslateX(ball.getTranslateX() + dx); ball.setTranslateY(ball.getTranslateY() + dy); } }); tl.getKeyFrames().add(moveBall); tl.play(); }
From source file:Main.java
@Override public void start(Stage stage) { DoubleProperty translate = new SimpleDoubleProperty(); stage.setTitle("Hello JavaFX"); Rectangle node1 = RectangleBuilder.create().x(0).y(0).width(10).height(10).fill(Color.RED).build(); node1.translateXProperty().bind(translate); Parent parent = GroupBuilder.create().children(node1).translateX(250).translateY(250).build(); stage.setScene(SceneBuilder.create().width(500).height(500).root(parent).build()); stage.show();//from w w w . ja v a 2s .c om TimelineBuilder.create().cycleCount(Timeline.INDEFINITE) .keyFrames(new KeyFrame(Duration.seconds(0), new KeyValue(translate, -50)), new KeyFrame(Duration.seconds(2), new KeyValue(translate, 250))) .build().play(); }
From source file:Main.java
@Override public void start(Stage stage) { final NumberAxis xAxis = new NumberAxis(); final CategoryAxis yAxis = new CategoryAxis(); final BarChart<Number, String> bc = new BarChart<Number, String>(xAxis, yAxis); bc.setTitle("Summary"); xAxis.setLabel("Value"); xAxis.setTickLabelRotation(90);/*from ww w . ja v a2 s .co m*/ yAxis.setLabel("Item"); XYChart.Series series1 = new XYChart.Series(); series1.setName("2003"); series1.getData().add(new XYChart.Data(2, itemA)); series1.getData().add(new XYChart.Data(20, itemB)); series1.getData().add(new XYChart.Data(10, itemC)); XYChart.Series series2 = new XYChart.Series(); series2.setName("2004"); series2.getData().add(new XYChart.Data(50, itemA)); series2.getData().add(new XYChart.Data(41, itemB)); series2.getData().add(new XYChart.Data(45, itemC)); XYChart.Series series3 = new XYChart.Series(); series3.setName("2005"); series3.getData().add(new XYChart.Data(45, itemA)); series3.getData().add(new XYChart.Data(44, itemB)); series3.getData().add(new XYChart.Data(18, itemC)); Timeline tl = new Timeline(); tl.getKeyFrames().add(new KeyFrame(Duration.millis(500), new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent actionEvent) { for (XYChart.Series<Number, String> series : bc.getData()) { for (XYChart.Data<Number, String> data : series.getData()) { data.setXValue(Math.random() * 100); } } } })); tl.setCycleCount(Animation.INDEFINITE); tl.play(); Scene scene = new Scene(bc, 800, 600); bc.getData().addAll(series1, series2, series3); stage.setScene(scene); stage.show(); }
From source file:spacetrader.controller.EncounterScreenController.java
/** * Initializes the controller class.// w w w . j a v a 2 s . c o m */ @Override public void initialize(URL url, ResourceBundle rb) { minuteMatrix = new Array2DRowRealMatrix(MINUTE_ARROW); hourMatrix = new Array2DRowRealMatrix(HOUR_ARROW); context = canvas.getGraphicsContext2D(); context.translate(375, 275); context.setFill(Color.CORNFLOWERBLUE); context.fillPolygon(minuteMatrix.getColumn(0), minuteMatrix.getColumn(1), 10); context.setFill(Color.MEDIUMAQUAMARINE); context.fillPolygon(hourMatrix.getColumn(0), hourMatrix.getColumn(1), 8); timeline = new Timeline(); timeline.setCycleCount(Timeline.INDEFINITE); inCount = 0; upDown = true; KeyFrame frame = new KeyFrame(Duration.seconds(1.0 / 24), new EventHandler<ActionEvent>() { public void handle(ActionEvent event) { System.out.println(inCount); context.clearRect(-375, -275, 750, 550); context.setStroke(Color.rgb(0, outCount, 127 + outCount)); context.setLineWidth(61); context.strokeOval(-230, -230, 460, 460); context.setStroke(Color.rgb(0, (outCount + 30) % 128, 127 + (outCount + 30) % 128)); context.strokeOval(-290, -290, 580, 580); context.setStroke(Color.rgb(0, (outCount + 60) % 128, 127 + (outCount + 60) % 128)); context.strokeOval(-350, -350, 700, 700); context.setStroke(Color.rgb(0, (outCount + 90) % 128, 127 + (outCount + 90) % 128)); context.setLineWidth(100); context.strokeOval(-430, -430, 860, 860); context.setFill(new LinearGradient(-200, -200, 200, 200, false, CycleMethod.NO_CYCLE, new Stop(0, Color.rgb(255, 255 - inCount, inCount)), new Stop(1, Color.rgb(255 - inCount, 0, 255)))); context.fillOval(-200, -200, 400, 400); minuteMatrix = minuteMatrix.multiply(minuteRotateMatrix); hourMatrix = hourMatrix.multiply(hourRotateMatrix); context.setFill(Color.CORNFLOWERBLUE); context.fillPolygon(minuteMatrix.getColumn(0), minuteMatrix.getColumn(1), 10); context.setFill(Color.MEDIUMAQUAMARINE); context.fillPolygon(hourMatrix.getColumn(0), hourMatrix.getColumn(1), 8); if (inCount % 20 < 10) { context.drawImage( new Image(Paths.get("image/star.png").toUri().toString(), 360, 360, false, false), -180, -180); } else { context.drawImage( new Image(Paths.get("image/star.png").toUri().toString(), 300, 300, false, false), -150, -150); } if (upDown) { inCount += 3; if (inCount >= 255) { upDown = false; } } else { inCount -= 3; if (inCount <= 0) { upDown = true; } } if (outCount >= 128) { outCount = 0; } else { outCount += 8; } } }); timeline.getKeyFrames().add(frame); timeline.play(); }
From source file:ubicrypt.ui.ctrl.MainController.java
@Override public void initialize(URL url, ResourceBundle resourceBundle) { fxml = substringBefore(substringAfterLast(url.getFile(), "/"), ".fxml"); log.debug("initialize fxml:{}, pgpservice:{}", fxml, pgpService); //file progress monitor progressEvents.subscribe(progress -> Platform.runLater(() -> { if (progress.isCompleted() || progress.isError()) { log.debug("progress completed"); if (!filesInProgress.remove(progress)) { log.warn("progress not tracked. progress file:{}, element:{}", progress.getProvenience().getFile()); }/*from w ww . ja va 2 s. c o m*/ Timeline timeline = new Timeline(new KeyFrame(Duration.seconds(2), ae -> { footer.setText(""); footer.setProgress(0D); })); timeline.play(); } else { filesInProgress.add(progress); } if (filesInProgress.isEmpty()) { return; } footer.setVisible(true); filesInProgress.stream().findFirst().ifPresent(pr -> { String file = abbreviate(pr.getProvenience().getFile().getPath().getFileName().toString(), 30); String target = abbreviate(pr.getDirection() == ProgressFile.Direction.inbound ? pr.getProvenience().getOrigin().toString() : pr.getTarget().toString(), 30); String text = file + " " + target; if (pr.getDirection() == ProgressFile.Direction.inbound) { text = target + " " + file; } footer.setText(text); footer.setProgress((double) progress.getChunk() / pr.getProvenience().getFile().getSize()); }); })); }
From source file:com.sunkur.springjavafxcontroller.screen.ScreensContoller.java
private boolean swapScreen(final Parent root) { final Group rootGroup = getScreenRoot(); final DoubleProperty opacity = rootGroup.opacityProperty(); if (!isScreenEmpty()) { Timeline fade = new Timeline(new KeyFrame(Duration.ZERO, new KeyValue(opacity, 1.0)), new KeyFrame(new Duration(250), new EventHandler<ActionEvent>() { @Override//ww w . ja v a 2s.c o m public void handle(ActionEvent t) { rootGroup.getChildren().remove(0); rootGroup.getChildren().add(0, root); Timeline fadeIn = new Timeline(new KeyFrame(Duration.ZERO, new KeyValue(opacity, 0.0)), new KeyFrame(new Duration(350), new KeyValue(opacity, 1.0))); fadeIn.play(); } }, new KeyValue(opacity, 0.0))); fade.play(); return true; } else { opacity.set(0.0); rootGroup.getChildren().add(0, root); Timeline fadeIn = new Timeline(new KeyFrame(Duration.ZERO, new KeyValue(opacity, 0.0)), new KeyFrame(new Duration(350), new KeyValue(opacity, 1.0))); fadeIn.play(); } if (!this.stage.isShowing()) { this.stage.show(); } return true; }
From source file:org.sociotech.unui.javafx.engine2d.AbstractWorld.java
private void initEventLoop() { final Duration fps = Duration.millis(1000 / (float) 60); final KeyFrame eventLoop = new KeyFrame(fps, new EventHandler<ActionEvent>() { public void handle(ActionEvent event) { // destroy entities on list getEntityManager().destroy(); updateEntities();/*from w ww .j a va2 s . c om*/ updateFps(); onPostUpdate(m_fps); } }); // Create Loop TimelineBuilder builder = TimelineBuilder.create(); builder.cycleCount(Animation.INDEFINITE); builder.keyFrames(eventLoop); m_eventLoop = builder.build(); }
From source file:jp.co.heppokoact.autocapture.FXMLDocumentController.java
@Override public void initialize(URL url, ResourceBundle rb) { // ???//from ww w. j av a2 s . c o m prop = new Properties(); if (CONFIG_FILE.exists()) { try (InputStream in = new FileInputStream(CONFIG_FILE)) { prop.loadFromXML(in); } catch (IOException e) { throw new RuntimeException("????????", e); } } // ???????? String saveDirectoryPath = prop.getProperty("saveDirectoryPath"); if (saveDirectoryPath != null) { File tempSaveDirectory = new File(saveDirectoryPath); if (tempSaveDirectory.exists()) { saveDirectory.set(tempSaveDirectory); } } // ??? saveDirectoryLabel.textProperty().bind(Bindings.createStringBinding(() -> { File sd = saveDirectory.get(); return (sd == null) ? "" : sd.getName(); }, saveDirectory)); areaStartXLabel.textProperty().bind(Bindings.convert(areaStartX)); areaStartYLabel.textProperty().bind(Bindings.convert(areaStartY)); areaEndXLabel.textProperty().bind(Bindings.convert(areaEndX)); areaEndYLabel.textProperty().bind(Bindings.convert(areaEndY)); nextPointXLabel.textProperty().bind(Bindings.convert(nextPointX)); nextPointYLabel.textProperty().bind(Bindings.convert(nextPointY)); prevPointXLabel.textProperty().bind(Bindings.convert(prevPointX)); prevPointYLabel.textProperty().bind(Bindings.convert(prevPointY)); // ??? stopButton.setDisable(true); // ???? captureService = new CaptureService(); captureTimeline = new Timeline(new KeyFrame(new Duration(CAPTURE_INTERVAL), e -> { captureService.restart(); })); captureTimeline.setCycleCount(Timeline.INDEFINITE); try { robot = new Robot(); } catch (AWTException e) { throw new RuntimeException("???????", e); } // ?? clip = new AudioClip(ClassLoader.getSystemResource("ayashi.wav").toString()); }
From source file:net.sourceforge.pmd.util.fxdesigner.MainDesignerController.java
private void initializeViewAnimation() { // gets captured in the closure final double defaultMainHorizontalSplitPaneDividerPosition = mainHorizontalSplitPane .getDividerPositions()[0];// w w w. j av a2 s. co m // show/ hide bottom pane bottomTabsToggle.selectedProperty().addListener((observable, wasExpanded, isNowExpanded) -> { KeyValue keyValue = null; DoubleProperty divPosition = mainHorizontalSplitPane.getDividers().get(0).positionProperty(); if (wasExpanded && !isNowExpanded) { keyValue = new KeyValue(divPosition, 1); } else if (!wasExpanded && isNowExpanded) { keyValue = new KeyValue(divPosition, defaultMainHorizontalSplitPaneDividerPosition); } if (keyValue != null) { Timeline timeline = new Timeline(new KeyFrame(Duration.millis(200), keyValue)); timeline.play(); } }); }