设计一款日历java_使用JavaFX制作一个简单的日历

使用JavaFX制作一个简单的日历

发布时间:2020-11-16 14:30:14

来源:亿速云

阅读:74

作者:Leah

这篇文章给大家介绍使用JavaFX制作一个简单的日历,内容非常详细,感兴趣的小伙伴们可以参考借鉴,希望对大家能有所帮助。

具体内容如下

1.先看效果:

df222fd760474c02c85ca8abf28d9630.png

2.代码:

1)ClockEdge.java类

这个类(Pane)主要是用来设置时钟边缘(为了美观对直了半天,其实想想也没必要~。~)

package com.javaBasic.javaFX;

import javafx.scene.layout.Pane;

import javafx.scene.paint.Color;

import javafx.scene.shape.Circle;

import javafx.scene.shape.Line;

import javafx.scene.text.Text;

/**

* @version 1.00 2016-10-15

* @author Administrator

* 功能:显示时钟边缘

*/

public class ClockEdge extends Pane{

private double w , h;

public ClockEdge(){

this(200, 200);

paint();

}

public ClockEdge(double w, double h){

this.w = w;

this.h = h;

paint();

}

public double getW() {

return w;

}

public void setW(double w) {

this.w = w;

paint();

}

public double getH() {

return h;

}

public void setH(double h) {

this.h = h;

paint();

}

public void paint(){

double clockRadius = Math.min(w, h) * 0.8 * 0.5;

double centerX = w / 2;

double centerY = h / 2;

Circle circle = new Circle(centerX, centerY, clockRadius);

circle.setFill(Color.WHITE);

circle.setStroke(Color.BLACK);

//假设一个字符宽7.6个像素,高8.8个像素

Text text1 = new Text(centerX + clockRadius * Math.sin(1 * Math.PI / 6) - 7.6 + 1.7 * (1 + Math.cos(2 * Math.PI / 6)) - 2.2 * Math.sin(2 * Math.PI / 6),

centerY - clockRadius * Math.cos(1 * Math.PI / 6) + 8.8 + 1.7 * Math.sin(2 * Math.PI / 6) - 2.2 * (1 - Math.cos(2 * Math.PI / 6)), "1");

Text text2 = new Text(centerX + clockRadius * Math.sin(2 * Math.PI / 6) - 7.6 + 1.7 * (1 + Math.cos(4 * Math.PI / 6)) - 2.2 * Math.sin(4 * Math.PI / 6),

centerY - clockRadius * Math.cos(2 * Math.PI / 6) + 8.8 + 1.7 * Math.sin(4 * Math.PI / 6) - 2.2 * (1 - Math.cos(4 * Math.PI / 6)), "2");

Text text3 = new Text(centerX + clockRadius * Math.sin(3 * Math.PI / 6) - 7.6 + 1.7 * (1 + Math.cos(6 * Math.PI / 6)) - 2.2 * Math.sin(6 * Math.PI / 6),

centerY - clockRadius * Math.cos(3 * Math.PI / 6) + 8.8 + 1.7 * Math.sin(6 * Math.PI / 6) - 2.2 * (1 - Math.cos(6 * Math.PI / 6)), "3");

Text text4 = new Text(centerX + clockRadius * Math.sin(4 * Math.PI / 6) - 7.6 + 1.7 * (1 + Math.cos(8 * Math.PI / 6)) + 2.2 * Math.sin(8 * Math.PI / 6),

centerY - clockRadius

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
下面是一个简单JavaFX代码,可以模拟风扇的转动效果: ```java import javafx.animation.Animation; import javafx.animation.RotateTransition; import javafx.application.Application; import javafx.scene.Scene; import javafx.scene.layout.Pane; import javafx.scene.paint.Color; import javafx.scene.shape.Arc; import javafx.scene.shape.Circle; import javafx.stage.Stage; import javafx.util.Duration; public class FanSimulation extends Application { @Override public void start(Stage primaryStage) { // 创建一个圆形 Circle circle = new Circle(150, 150, 100); circle.setFill(Color.TRANSPARENT); circle.setStroke(Color.BLACK); // 创建三个扇形 Arc arc1 = new Arc(150, 150, 80, 80, 0, 30); arc1.setType(ArcType.ROUND); arc1.setFill(Color.RED); arc1.setStroke(Color.BLACK); Arc arc2 = new Arc(150, 150, 80, 80, 90, 30); arc2.setType(ArcType.ROUND); arc2.setFill(Color.BLUE); arc2.setStroke(Color.BLACK); Arc arc3 = new Arc(150, 150, 80, 80, 180, 30); arc3.setType(ArcType.ROUND); arc3.setFill(Color.GREEN); arc3.setStroke(Color.BLACK); // 创建一个面板并添加圆形和扇形 Pane pane = new Pane(); pane.getChildren().addAll(circle, arc1, arc2, arc3); // 创建一个旋转动画 RotateTransition rotateTransition = new RotateTransition(Duration.seconds(2), pane); rotateTransition.setByAngle(360); rotateTransition.setCycleCount(Animation.INDEFINITE); rotateTransition.play(); // 创建一个场景并将面板添加到场景中 Scene scene = new Scene(pane, 300, 300); // 将场景添加到舞台并显示舞台 primaryStage.setScene(scene); primaryStage.show(); } public static void main(String[] args) { launch(args); } } ``` 上述代码创建了一个圆形和三个扇形,然后将它们添加到面板中。接着创建一个旋转动画,并将面板添加到动画中,最后将面板添加到场景中并显示舞台。运行程序后,将会看到一个旋转的风扇。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值