Java Reference
In-Depth Information
FadeTransition fadeOut = new
FadeTransition(Duration.millis(500), imageView);
fadeOut.setFromValue(1.0);
fadeOut.setToValue(0.0);
fadeOut.setOnFinished((ActionEvent ae) -> {
imageView.setImage(nextImage);
});
FadeTransition fadeIn = new
FadeTransition(Duration.millis(500), imageView);
fadeIn.setFromValue(0.0);
fadeIn.setToValue(1.0);
SequentialTransition seqTransition = new
SequentialTransition();
seqTransition.getChildren().addAll(fadeOut, fadeIn);
return seqTransition;
For the last requirements relating to fading in and out, use the button controls. Use
the FadeTransition to create a ghostly animated effect. For starters, you create an
EventHandler (more specifically, an EventHandler<MouseEvent> via a
lambda expression). It is easy to add mouse events to the scene; all you have to do is
override the handle() method where the inbound parameter is a MouseEvent type
(the same as its formal type parameter). Inside of the lambda , you create an instance
of a FadeTransition object by using the constructor that takes the duration and
node as parameters. Next, you'll notice the setFromValue() and setToValue()
methods that are called to interpolate values between 1.0 and 0.0 for the opacity level,
causing the fade in effect to occur. The following code adds an EventHandler to
create the fade in effect when the mouse cursor is positioned inside of the scene:
// Fade in button controls
scene.setOnMouseEntered((MouseEvent me) -> {
FadeTransition fadeButtons = new
FadeTransition(Duration.millis(500), buttonGroup);
fadeButtons.setFromValue(0.0);
fadeButtons.setToValue(1.0);
fadeButtons.play();
});
Search WWH ::




Custom Search