0% found this document useful (0 votes)
100 views

Java Örnek

This Java code defines an application that extends the Application class. It creates a circle and text shape on a pane and defines two animation transitions - a path transition that moves the text around the circle and a fade transition that fades the text in and out. It adds mouse interaction to pause and resume the animations when clicked.

Uploaded by

asa
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
100 views

Java Örnek

This Java code defines an application that extends the Application class. It creates a circle and text shape on a pane and defines two animation transitions - a path transition that moves the text around the circle and a fade transition that fades the text in and out. It adds mouse interaction to pause and resume the animations when clicked.

Uploaded by

asa
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

package javaapplication4;

import javafx.animation.FadeTransition;
import javafx.animation.PathTransition;
import javafx.animation.Timeline;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.layout.Pane;
import javafx.scene.paint.Color;
import javafx.scene.shape.Circle;
import javafx.scene.text.Text;
import javafx.stage.Stage;
import javafx.util.Duration;
/**
*
* @author Burhan
*/
public class JavaApplication4 extends Application {
boolean a;
@Override
public void start(Stage primaryStage) throws Exception {
Pane pane = new Pane();
double width = 600;
double height = 600;
Scene scene = new Scene(pane, width, height);
double radius = Math.min(width, height) * 0.25;
Circle c = new Circle(width / 2, height / 2, radius, Color.TRANSPARENT);
c.setRotate(180);
Text text = new Text("Burhan G�m�soy");

//Create a path transition.

PathTransition pt = new PathTransition();


//Set the duration of this animation as 10000

pt.setDuration(Duration.millis(10000));
//The path will be the circle
pt.setPath(c);
//The node will be the text
pt.setNode(text);

pt.setOrientation(
PathTransition.OrientationType.ORTHOGONAL_TO_TANGENT);

//The animation will cycle indefinite number of cycles


pt.setCycleCount(Timeline.INDEFINITE);
pt.setAutoReverse(false);
pt.play(); // Start animation

//Create a fade transition on the text


//Set the duration of this animation as 5000
FadeTransition ft = new FadeTransition(Duration.millis(5000), text);
//The animation fade value will change from 1.0 to 0.0
ft.setFromValue(1.0);
ft.setToValue(0.0);

//The animationwill automatically reverse


ft.setAutoReverse(true);
//The animation will cycle indefinite number of cycles
ft.setCycleCount(Timeline.INDEFINITE);

ft.play(); // Start animation

//When the mouse is pressed on the pane the animations will pause
// pane.setOnMousePressed(e->{
// text.setText("sdfsdfsdfs");
// //pt.pause();
// //ft.pause();
// });
//pane.setOnMouseReleased(e -> {
// pt.play();
// ft.play();
// });

pane.setOnMouseClicked(e -> {
a=!a;
if(a){
pt.pause();
ft.pause();

}
else{
pt.play();
ft.play();

}
});

//When the mouse is released from the pane the animations will continue to
play

pane.getChildren().addAll(text);
primaryStage.setScene(scene);
primaryStage.setTitle("WEEK 10");
primaryStage.show();
}

public static void main(String[] args) {


Application.launch(args);
}
}

You might also like