使用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://www.jxjierui.cn/article/dssoep.html


咨询
建站咨询
