javafx的练习三
package com.meyacom.first;
import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.paint.Color;
import javafx.scene.paint.CycleMethod;
import javafx.scene.paint.LinearGradient;
import javafx.scene.paint.Stop;
import javafx.scene.shape.Circle;
import javafx.scene.shape.Rectangle;
import javafx.scene.shape.StrokeType;
import javafx.stage.Stage;
/**
?*
?* 类名:ThirdDemo
?*
?* @author 朱湘鄂
?* @Created Date:2011-7-14 @Created Time:下午02:53:34
?* @Copyright? 2011-2023 MYC Corporation, All Rights Reserved.
?* 这个是在第二个例子的基础上添加的一个效果
?*
?*/
public class ThirdDemo extends Application{
??? /**
??? ?* 方法用途:
??? ?* 方法名称: main
??? ?* @param args
??? ?*???? 返回类型:void
??? ?*???? 返回值说明:
??? ?*/
??? public static void main(String[] args) {
??? ??? ??? Application.launch(args);//这个方法是唯一在main方法里面调用的
??? }
??? @Override//重写start方法
??? public void start(Stage arg0) throws Exception {
??? ??? Group root = new Group();//创建一个根节点
??? ???
??? ??? Scene scene = new Scene(root,800,600,Color.BLACK);
??? ??? arg0.setScene(scene);
??? ???
??? ??? Group cycle = new Group();
??? ??? for(int i=0;i<30;i++){
??? ??? ??? Circle circle = new Circle(150,Color.web("white",0.05));
??? ??? ??? circle.setStrokeType(StrokeType.OUTSIDE);
??? ??? ??? circle.setStroke(Color.web("white",0.16));
??? ??? ??? circle.setStrokeWidth(4);
??? ??? ??? cycle.getChildren().add(circle);
??? ??? }
??? ??? //cycle.setEffect(new BoxBlur(10,10,3));//添加模糊效果
??? ???
??? ??? Rectangle colors = new Rectangle(scene.getWidth(),scene.getHeight(),//创建一个矩形的效果图
??? ??? ??? ??? new LinearGradient(0f,1f,1f,0f,true,CycleMethod.NO_CYCLE,new //从左下角0,0开始,在右下角1,1结束的一个线性填充
??? ??? ??? ??? ??? ??? Stop[]{//stop序列代表一个渐变的点
??? ??? ??? ??? ??? ??? ??? new Stop(0,Color.web("#f8bd55")),
??? ??? ??? ??? ??? ??? ??? new Stop(0.14,Color.web("#c0fe56")),
??? ??? ??? ??? ??? ??? ??? new Stop(0.28,Color.web("#5dfbc1")),
??? ??? ??? ??? ??? ??? ??? new Stop(0.43,Color.web("#64c2f8")),
??? ??? ??? ??? ??? ??? ??? new Stop(0.57,Color.web("#be4af7")),
??? ??? ??? ??? ??? ??? ??? new Stop(0.71,Color.web("#ed5fc2")),
??? ??? ??? ??? ??? ??? ??? new Stop(0.85,Color.web("#ef504c")),
??? ??? ??? ??? ??? ??? ??? new Stop(1,Color.web("#f2660f")),
??? ??? ??? ??? }));
??? ???
??? ??? root.getChildren().add(colors);//添加渐变到容器root中
??? ???
??? ??? root.getChildren().add(cycle);//将圆添加到背景中
??? ???
??? ??? arg0.setVisible(true);//让stage可见
??? }
???
???
???
???
???
???
???
???
???
???
???
???
???
???
???
???
???
???
???
???
???
???
???
???
???
???
}