import javafx.animation.Animation;
import javafx.animation.KeyFrame;
import javafx.animation.Timeline;
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.paint.Color;
import javafx.scene.shape.Circle;
import javafx.stage.Stage;
import javafx.util.Duration; public class Main extends Application {
static int dx = ;
static int dy = ; public static void main(String[] args) {
Application.launch(args);
} @Override
public void start(final Stage primaryStage) {
primaryStage.setTitle("Animation");
Group root = new Group();
Scene scene = new Scene(root, , , Color.WHITE); primaryStage.setScene(scene);
addBouncyBall(scene);
primaryStage.show();
}
private void addBouncyBall(final Scene scene) {
final Circle ball = new Circle(, , ); final Group root = (Group) scene.getRoot();
root.getChildren().add(ball); Timeline tl = new Timeline();
tl.setCycleCount(Animation.INDEFINITE);
KeyFrame moveBall = new KeyFrame(Duration.seconds(.),
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 < || xMax > scene.getWidth()) {
dx = dx * -;
}
if (yMin < || yMax > scene.getHeight()) {
dy = dy * -;
} ball.setTranslateX(ball.getTranslateX() + dx);
ball.setTranslateY(ball.getTranslateY() + dy); }
}); tl.getKeyFrames().add(moveBall);
tl.play();
}
}

最新文章

  1. 1Z0-053 争议题目解析46
  2. 用dos命令备份和恢复sql server 数据库
  3. [UCSD白板题] Compute the Edit Distance Between Two Strings
  4. struts2的两个核心配置文件
  5. SQLserver的存储过程
  6. 【转】Git详解之一:Git起步
  7. java技术栈:一、java编程语言概述
  8. hg 证书验证失败
  9. 认识&lt;img&gt;标签,为网页插入图片
  10. poj Pie
  11. 《python基础教程》笔记之 基础知识
  12. 【原创整理,基于JavaScript的创建对象方式的集锦】
  13. IOS 使用动态库(dylib)和动态加载framework
  14. 解读Java内部类
  15. rsync源目录写法的一点小细节
  16. Shell脚本 | 性能测试之CPU占有率
  17. UVA1599-Ideal Path(BFS进阶)
  18. [IR] Arithmetic Coding
  19. Mysql分页之limit用法与limit优化
  20. 《Spring2之站立会议7》

热门文章

  1. vmware workstation虚拟机克隆后不能上网(桥接模式下)
  2. spinlock参考资料
  3. 错排公式 全排列函数 next_permitation(a,a+n)
  4. Centos安装masscan
  5. NodeJS学习笔记 (15)二进制数据-buffer(ok)
  6. HDU-1789 Doing Homework again 贪心问题 有时间限制的最小化惩罚问题
  7. 单调队列&amp;单调栈归纳
  8. iOS 全局修改UINavigation 后退按钮
  9. windows server,无桌面服务器 , 批处理更改时区
  10. 分享:FIFO 同步、异步以及Verilog代码实现