中南大学java实验报告-运用javafx画时钟运用javafx实现时钟动画内容摘要:

getSecond() { return second。 } /** 设置一个新的秒数 */ public void setSecond(int second) { = second。 paintClock()。 } /** 返回时钟面板的宽度 */ public double getW() { return w。 } /** 设置时钟面板的宽度 */ public void setW(double w) { = w。 paintClock()。 } /** 返回时钟面板的高度 */ public double getH() { return h。 } /** 设置时钟面板的高度 */ public void setH(double h) { = h。 paintClock()。 } /** 设置时钟的时间为当前时间 */ public void setCurrentTime() { // 构造一个日历为当前的日期和时间 Calendar calendar = new GregorianCalendar()。 // 设置当前的小时,分,秒 = ()。 = ()。 = ()。 paintClock()。 // 重新绘制时钟 } /** 画钟函数 */ private void paintClock() { // 初始化时钟参数 double clockRadius = (w, h) * *。 //时钟半径 double centerX = w / 2。 double centerY = h / 2。 //时钟中心坐标 // 画圆 Circle circle = new Circle(centerX, centerY, clockRadius)。 ()。 //设置圆的内部填充颜色为白色 ()。 //设置圆的线条为黑色 //设置时钟上的数字 1到 12 Text t1 = new Text(centerX 5, centerY clockRadius + 12, 12)。 Text t2 = new Text(centerX clockRadius + 3, centerY + 5, 9)。 Text t3 = new Text(centerX + clockRadius 10, centerY + 3, 3)。 Text t4 = new Text(centerX 3, centerY + clockRadius 3, 6)。 Text t5 = new Text(centerX clockRadius + 42, centerY clockRadius +27, 11)。 Text t6 = new Text(centerX clockRadius + 10, centerY clockRadius +65, 10)。 Text t7 = new Text(centerX clockRadius + 10, centerY +clockRadius 55, 8)。 Text t8 = new Text(centerX clockRadius + 45, centerY +clockRadius 17, 7)。 Text t9 = new Text(centerX + clockRadius 52, centerY clockRadius +27, 1)。 Text t10 = new Text(centerX + clockRadius 20, centerY clockRadius +65, 2)。 Text t11 = new Text(centerX + clockRadius 20, centerY +clockRadius 55, 4)。 Text t12 = new Text(centerX + clockRadius 50, centerY +clockRadius 17, 5)。 // 绘制秒针 double sLength = clockRadius *。 double secondX = centerX + sLength * (second * (2 * / 60))。 double secondY = centerY sLength * (second * (2 * / 60))。 Line sLine = new Line(centerX, centerY, secondX, secondY)。 ()。 //设置秒针的颜色为红色 // 绘制分针 double mLength = clockRadius *。 double xMinute = centerX + mLength * (minute * (2 * / 60))。 double minuteY = centerY mLength * (minute * (2 * / 60))。 Line mLine = new Line(centerX, centerY, xMinute, minuteY)。 ()。 //设置分针的颜色为蓝色 // 绘制时针 double hLength = clockRadius *。 double hourX = centerX + hLength * ((hour % 12 + minute / ) * (2 * / 12))。 double hourY = centerY hLength * ((hour % 12 + minute / ) * (2 * / 12))。 Line hLine = new Line(centerX, centerY, hourX, hourY)。 ()。 //设置时针的颜色为绿色 getChildren().clear()。 //将数字 1 到 12加载在时钟指定位置 getChildren().addAll(circle, t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, sLine, mLine, hLine)。 } } public class DisplayClock extends Application { @Override // 覆盖在应用程序中的 start 方法 public void start(Stage primaryStage) { //start(Stage)方法 // 创建一个时钟和标签 ClockPane clock = new ClockPane()。
阅读剩余 0%
本站所有文章资讯、展示的图片素材等内容均为注册用户上传(部分报媒/平媒内容转载自网络合作媒体),仅供学习参考。 用户通过本站上传、发布的任何内容的知识产权归属用户或原始著作权人所有。如有侵犯您的版权,请联系我们反馈本站将在三个工作日内改正。