Package com.vengo.test.ui

Source Code of com.vengo.test.ui.Model

package com.vengo.test.ui;

import java.io.File;

import javafx.animation.FadeTransition;
import javafx.animation.KeyFrame;
import javafx.animation.Timeline;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Group;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.util.Duration;

class Model
{
 
 
  ImageView[] ivScene = new ImageView[2];

     void play()
     {
      // System.out.print(imagepath);
       timeline.play();
     }

     void stop()
     {
        timeline.stop();
     }


   Model(final Group root)
   {
      String[] names = new String[]
      {
       
         "billyboy_ad",
         "chapfix_ad",      
         "luckybloke_ad",
         "aquaphor_ad",
         "tridentwhite_ad",
         "jila_ad",
        
      };

      final ImageView[] ivArray = new ImageView[names.length];
      for (int i = 0; i < names.length; i++)
         //ivArray[i] = new ImageView(new Image(getClass().getResourceAsStream(names[i]+".png")));
        ivArray[i] = new ImageView(new Image("file:///C:/vengo/images/"+names[i]+".png"));
      ivScene[0] = ivArray[1];
      ivScene[1] = ivArray[0];

      final FadeTransition fadeout = new FadeTransition();
      fadeout.setNode(ivScene[1]);
      fadeout.setFromValue(1.0);
      fadeout.setToValue(0.0);
      fadeout.setDuration(Duration.valueOf("2000ms"));
      EventHandler<ActionEvent> eh;
      eh = new EventHandler<ActionEvent>()
      {
         public void handle(ActionEvent ae)
         {
            ImageView ivTemp = ivScene[0];
            ivScene[0] = ivScene[1];
            ivScene[1] = ivTemp;
            fadeout.setNode(ivScene[1]);
            ivScene[0] = ivArray[i];
            ivScene[0].setOpacity(1.0);
            if (++i == ivArray.length)
               i = 0;
            root.getChildren().setAll(ivScene[0], ivScene[1]);
         }
      };
      fadeout.setOnFinished(eh);

      timeline = new Timeline();
      timeline.setCycleCount(Timeline.INDEFINITE);
      KeyFrame[] kf = new KeyFrame[1];
      eh = new EventHandler<ActionEvent>()
      {
         public void handle(ActionEvent ae)
         {
            fadeout.playFromStart();
         }
      };
      kf[0] = new KeyFrame(Duration.valueOf("4000ms"), eh);
      timeline.getKeyFrames().addAll(kf);
   }

   private int i = 2;
   private Timeline timeline;
}
TOP

Related Classes of com.vengo.test.ui.Model

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.