Pressing the Start button will start the Transition to a fill color of green.
The initial color is red, so after 5 seconds it turns to green, and it will interpolate in between. The button becomes invisible after it is clicked.
package ex96;
import javafx.animation.FillTransition;
import javafx.application.Application;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.effect.DropShadow;
import javafx.scene.layout.StackPane;
import javafx.scene.layout.VBox;
import javafx.scene.paint.Color;
import javafx.scene.shape.Rectangle;
import javafx.scene.text.Font;
import javafx.scene.text.Text;
import javafx.stage.Stage;
import javafx.util.Duration;
public class Ex96 extends Application {
@Override
public void start(Stage stage) {
DropShadow dropShadow = new DropShadow();
dropShadow.setOffsetX(5);
dropShadow.setOffsetY(5);
dropShadow.setColor(Color.GOLD);
Rectangle rect = new Rectangle(200, 100, Color.RED);
rect.setStrokeWidth(5);
rect.setArcWidth(30);
rect.setArcHeight(30);
rect.setStroke(Color.BLUE);
rect.setEffect(dropShadow);
Text text = new Text("FillTransition");
text.setFont(Font.font("Geogia", 32));
StackPane stackPane = new StackPane(rect, text);
FillTransition fillTransition =
new FillTransition(Duration.seconds(5), rect);
fillTransition.setToValue(Color.GREEN);
Button button = new Button("Start");
button.setOnAction(e -> {
fillTransition.play();
button.setVisible(false);
});
VBox vbox = new VBox(50, stackPane, button);
vbox.setAlignment(Pos.CENTER);
vbox.setStyle("-fx-background-color: gray");
Scene scene = new Scene(vbox, 400, 300);
stage.setTitle("Example 96. FillTransition");
stage.setScene(scene);
stage.show();
}
public static void main(String[] args) {
launch();
}
}
This is the output during the animation:
No comments:
Post a Comment