Java multiple slide switch effects of classic

  • 2020-04-01 01:41:20
  • OfStack

Function realization:

1. ImageLoader implementation of image loading class:

1) block queue images = new arrayblockingqueue e< > (2);

2) Image eof is used to represent the end of the Image queue :Image eof = new WritableImage(1, 1);

3) looping to read the specified image. Because the queue is blocked, the thread will automatically block when the queue is full.


public void run() { 
        int id = 0; 
        try { 
            while (true) { 
                String path = resources[id]; 
                InputStream is = getClass().getResourceAsStream(path); 
                if (is != null) { 
                    Image image = new Image(is, width, height, true, true); 
                    if (!image.isError()) { 
                        images.put(image); 
                    } 
                } 
                id++; 
                if (id >= resources.length) { 
                    id = 0; 
                } 
            } 
        } catch (Exception e) { 
        } finally { 
            if (!cancelled) { 
                try { 
                    images.put(eof); 
                } catch (InterruptedException e) { 
                } 
            } 
        } 
    } 

Take the arc toggle picture as an example: first, define the LengthTransition change effect: set the change time and the change relationship between the number of radians and the time.


class LengthTransition extends Transition { 
    Arc arc; 
    public LengthTransition(Duration d, Arc arc) { 
        this.arc = arc; 
        setCycleDuration(d); 
    } 
    @Override
    protected void interpolate(double d) { 
        arc.setLength(d * 360); 
    } 
} 

  Then set the image cascading effect:


group.setBlendMode(BlendMode.SRC_OVER); 
next.setBlendMode(BlendMode.SRC_ATOP); 
  And the fade-out effect of the previous image :
FadeTransition ft = new FadeTransition(Duration.seconds(0.2), mask2); 
  Finally, both effects are executed simultaneously :
ParallelTransition pt = new ParallelTransition(lt, ft); 

  Effect:

< img border = 0 SRC = "/ / files.jb51.net/file_images/article/201303/2013330130306440.jpg" >


Related articles: