当前位置: 代码迷 >> Web前端 >> javafx的练习题四
  详细解决方案

javafx的练习题四

热度:128   发布时间:2012-11-22 00:16:41.0
javafx的练习四

package com.meyacom.first;

import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.effect.BlendMode;
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;
/**
?*
?* 类名:FourthDemo
?*
?* @author 朱湘鄂
?* @Created Date:2011-7-14 @Created Time:下午03:00:03
?* @Copyright? 2011-2023 MYC Corporation, All Rights Reserved.
?* 这个实例是在第三个实例的基础上来做的
?*/
public class FourthDemo 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);//不将圆添加到背景中
??? ???
??? ??? //应用混合模式
??? ??? Group blendModeGroup = new Group(//创建混合模式
??? ??? ??? ??? ??? ??? new Group(new Rectangle(scene.getWidth(),scene.getHeight(),Color.BLACK),cycle),colors);//该混合模式包含两个子元素
??? ??? //第一个是一个匿名的Group,第二个是上面创建的那个cycle
??? ??? blendModeGroup.setBlendMode(BlendMode.OVERLAY);//
??? ??? root.getChildren().add(blendModeGroup);//添加blendModeGroup的场景图
??? ??? arg0.setVisible(true);//让stage可见
??? }

???
???
???
???
???
???
???
???
???

}

  相关解决方案