成都创新互联网站制作重庆分公司

使用JavaFX如何实现一个时钟效果-创新互联

这篇文章将为大家详细讲解有关使用JavaFX如何实现一个时钟效果,文章内容质量较高,因此小编分享给大家做个参考,希望大家阅读完这篇文章后对相关知识有一定的了解。

峨山县网站建设公司创新互联公司,峨山县网站设计制作,有大型网站制作公司丰富经验。已为峨山县数千家提供企业网站建设服务。企业网站搭建\外贸网站制作要多少钱,请找那个售后服务好的峨山县做网站的公司定做!

具体内容如下

效果图

用当前时间创建时钟,绘制表盘。
钟表是静止的。让指针动起来,请参照:绘制简易时钟(二)


使用JavaFX如何实现一个时钟效果

主函数文件 ShowClock:

package primier;

import javafx.application.Application;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.stage.Stage;
import javafx.scene.paint.Color;
import javafx.scene.layout.*;
import javafx.scene.control.*;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.shape.Line;

public class ShowClock extends Application {
 @Override //Override the start method in the Application class
 public void start(Stage primaryStage) {
  // 创建时钟面板
  ClockPane clock = new ClockPane();
  // 当前时间整理为字符串
  String timeString = clock.getHour() + ":" + clock.getMinute()
    + ":" + clock.getSecond();
  Label lbCurrentTime = new Label(timeString);

  BorderPane pane = new BorderPane();
  pane.setCenter(clock);
  pane.setBottom(lbCurrentTime);
  // 将时钟字符串设为靠上居中
  BorderPane.setAlignment(lbCurrentTime, Pos.TOP_CENTER);

  Scene scene = new Scene(pane, 250,250);
  primaryStage.setTitle("Display Clock");
  primaryStage.setScene(scene);
  primaryStage.show();
 }
 public static void main (String[] args) {
  Application.launch(args);
 }
}

当前名称:使用JavaFX如何实现一个时钟效果-创新互联
文章源于:http://cxhlcq.com/article/dssoep.html

其他资讯

在线咨询

微信咨询

电话咨询

028-86922220(工作日)

18980820575(7×24)

提交需求

返回顶部