java *** 制作圣诞贺卡

博主分享了一段Java代码,用于制作圣诞贺卡。代码包括了不同形状(泡泡、球、星星、三角形和长方形)的绘制,并且详细列出了触发事件类,以及屏幕边缘的处理逻辑。
摘要由CSDN通过智能技术生成

前几天用写了个圣诞贺卡的软件,今天有空把代码贴一下。


主文件:

package test;

import javafx.application.*;
import javafx.scene.control.*;
import javafx.scene.effect.BlendMode;
import javafx.scene.effect.BoxBlur;
import javafx.scene.image.*;
import javafx.util.*;
import javafx.animation.*;
import javafx.geometry.*;
import javafx.scene.Scene.*;
import javafx.stage.Stage;
import static java.lang.Math.random;
import javafx.util.Duration;
import javafx.event.*;
import javafx.scene.*;
import javafx.beans.property.*;
import javafx.collections.FXCollections;
import javafx.beans.*;
import javafx.scene.control.*;
import javafx.scene.layout.*;
import javafx.scene.media.AudioClip;
import javafx.scene.paint.*;
import javafx.scene.shape.*;
import javafx.scene.text.*;
import javafx.scene.transform.*;
import javafx.stage.*;
import javafx.geometry.*;
import javafx.scene.input.*;
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.Random;


public class SimpleCircle extends Application {
	public void start(Stage primaryStage) {
		//上下左右
		LeftEvent left=new LeftEvent();
		ButtomEvent bottom=new ButtomEvent();
		RightEvent right=new RightEvent();
		
		//中央画面
		StackPane gxpaneForFrame=new StackPane();
		gxpaneForFrame.setStyle("-fx-background-color:white");
		//背景
		StackPane gxbk=new StackPane();
		gxbk.getChildren().add(left.getBk());
		//文字
		StackPane gxtxt=new StackPane();
		gxtxt.getChildren().add(bottom.getText());
		//装饰
		StackPane gxdeco=new StackPane();
		gxdeco.getChildren().add(right.getDecorate());
		gxpaneForFrame.getChildren().addAll(gxdeco,gxbk,gxtxt);
		
		//显示标题,上方
		HBox gxpaneForTitle=new HBox(20);
		gxpaneForTitle.setPadding(new Insets(5,5,5,5));
		gxpaneForTitle.setAlignment(Pos.CENTER);
		Text title=new Text("Make Your Own Christmas Card");
		title.setFont(Font.font("Comic Sans MS",FontWeight.BOLD,30));
		title.setFill(Color.rgb(192, 5, 0));
		//全部清除
		RadioButton gxrbCLR=new RadioButton("CLR ALL");
		gxrbCLR.setFont(Font.font("Comic Sans MS",FontWeight.BOLD,15));
		gxrbCLR.setTextFill(Color.rgb(156, 181, 177));
		gxrbCLR.setOnAction(e->{
			if(gxrbCLR.isSelected()){
			left.gxCLR();
			right.gxCLR();}
		});
		gxpaneForTitle.getChildren().addAll(title,gxrbCLR);

		//控制面板
		BorderPane pane=new BorderPane();
		pane.setTop(gxpaneForTitle);
		pane.setBottom(bottom.getPane());
		pane.setCenter(gxpaneForFrame);
		pane.setLeft(left.getPane());
		pane.setRight(right.getPane());
		
		Scene scene=new Scene(pane);
		primaryStage.setTitle("miao");
		primaryStage.setScene(scene);
		primaryStage.show();
	}
}


显示的泡泡类:

这个是球:

package test;

import static java.lang.Math.random;
import javafx.animation.FadeTransition;
import javafx.animation.ParallelTransition;
import javafx.animation.ScaleTransition;
import javafx.animation.Timeline;
import javafx.animation.Animation.Status;
import javafx.scene.paint.Color;
import javafx.scene.shape.Circle;
import javafx.util.Duration;

public class ballbase extends Circle{
	protected FadeTransition gxfade;
	protected ScaleTransition gxscale;
	private ParallelTransition gxpara;
	
	public ballbase(){
		super(random()*10);
		setFill(Color.rgb(156, 181, 177));
	//	this.setEffect(new BoxBlur());
		//设置透明度
		gxfade=new FadeTransition(Duration.millis(3000),this);
		gxfade.setFromValue(random());
		gxfade.setToValue(random());
		gxfade.setCycleCount(Timeline.INDEFINITE);
		gxfade.setAutoReverse(true);
		//设置大小变换
		gxscale=new ScaleTransition(Duration.millis(3000),this);
		gxscale.setToX(1.5);
		gxscale.setToY(1.5);
		gxscale.setCycleCount(Timeline.INDEFINITE);
		gxscale.setAutoReverse(true);
		setCenterX(random()*900);
		setCenterY(random()*450);
		gxpara=new ParallelTransition();
		gxpara.getChildren().addAll(gxfade,gxscale);
		gxpara.play();
		
	}

	/*public int getstatus(){
		if(gxpara.getStatus()==Status.RUNNING)
			return 0;
		else if(gxpara.getStatus()==Status.PAUSED)
			return 1;
		else return 2;
	}*/
}


这个是星星:

package test;

import static java.lang.Math.random;
import javafx.animation.FadeTransition;
import javafx.animation.ParallelTransition;
import javafx.animation.ScaleTransition;
import javafx.animation.Timeline;
import javafx.collections.ObservableList;
import javafx.animation.Animation.Status;
import javafx.scene.paint.Color;
import javafx.scene.shape.*;
import javafx.util.Duration;

public class starbase extends Polygon {
	protected FadeTransition gxfade;
	protected ScaleTransition gxscale;
	private ParallelTransition gxpara;
	private double centerX,centerY;
	private double radius;
	private ObservableList<Double> list;
	
	public starbase(){
		list=this.getPoints();
		centerX=random()*850;
		centerY=random()*450;
		radius=random()*10;
		for(int i=0;i<10;++i){
			double now=i%2+1;
			list.add(centerX+radius/now*Math.cos(Math.PI*i/5+2.5/Math.PI));
			list.add(centerY+radius/now*Math.sin(Math.PI*i/5+2.5/Math.PI));
		}
		setFill(Color.color(random() * 0.5, random() * 0.5+ 0.5, 0.).darker());
		//设置透明度
		gxfade=new FadeTransition(Duration.millis(3000),this);
		gxfade.setFromValue(random());
		gxfade.setToValue(random());
		gxfade.setCycleCount(Timeline.INDEFINITE);
		gxfade.setAutoReverse(true);
		//设置大小变换
		gxscale=new ScaleTransition(Duration.millis(3000),this);
		gxscale.setToX(1.5);
		gxscale.setToY(1.5);
		gxscale.setCycleCount(Timeline.INDEFINITE);
		gxscale.setAutoReverse(true);
		gxpara=new ParallelTransition();
		gxpara.getChildren().addAll(gxfade,gxscale);
		gxpara.play();
}

	public int getstatus(){
		if(gxpara.getStatus()==Status.RUNNING)
			return 0;
		else if(gxpara.getStatus()==Status.PAUSED)
			return 1;
		else return 2;
	}
}


这个是三角形:

package test;

import static java.lang.Math.random;
import javafx.animation.FadeTransition;
import javafx.animation.ParallelTransition;
import javafx.animation.ScaleTransition;
import javafx.animation.Timeline;
import javafx.collections.ObservableList;
import javafx.animation.Animation.Status;
import javafx.scene.paint.Color;
import javafx.scene.shape.*;
import javafx.util.Duration;

public class trianglebase extends Polygon {
	protected FadeTransition gxfade;
	protected ScaleTransition gxscale;
	private ParallelTransition gxpara;
	private double centerX,centerY;
	private double radius;
	private ObservableList<Double> list;
	
	public trianglebase(){
		list=this.getPoints();
		centerX=random()*850;
		centerY=random()*450;
		radius=random()*10;
		for(int i=0;i<3;++i){
			list.add(centerX+radius*Math.cos(2*Math.PI*i/3)+3.0/Math.PI);
			list.add(centerY+radius*Math.sin(2*Math.PI*i/3)+3.0/Math.PI);
		}
		setFill(Color.color(random() * 0.5, random() * 0.5+ 0.5, 0.).darker());
		//设置透明度
		gxfade=new FadeTransition(Duration.millis(3000),this);
		gxfade.setFromValue(random());
		gxfade.setToValue(random());
		gxfade.setCycleCount(Timeline.INDEFINITE);
		gxfade.setAutoReverse(true);
		//设置大小变换
		gxscale=new ScaleTransition(Duration.millis(3000),this);
		gxscale.setToX(1.5);
		gxscale.setToY(1.5);
		gxscale.setCycleCount(Timeline.INDEFINITE);
		gxscale.setAutoReverse(true);
		gxpara=new ParallelTransition();
		gxpara.getChildren().addAll(gxfade,gxscale);
		gxpara.play();
}

	public int getstatus(){
		if(gxpara.getStatus()==Status.RUNNING)
			return 0;
		else if(gxpara.getStatus()==Status.PA
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值