Commit 5e6c9f45 authored by jackw's avatar jackw

Bounce

parents
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="output" path="bin"/>
</classpath>
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>sem2-formative-</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
import javafx.application.*;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Bounds;
import javafx.stage.*;
import javafx.util.Duration;
import javafx.scene.*;
import javafx.scene.paint.*;
import javafx.scene.canvas.*;
import javafx.scene.shape.*;
import javafx.animation.*;
import java.util.*;
public class Bounce extends Application {
public void setup() {
}
public void start(Stage s) {
Canvas canvas = new Canvas();
Group root = new Group();
Scene scene = new Scene(root, 700, 700, Color.LIGHTGREY);
Circle ball = new Circle(20, Color.GREEN);
ball.relocate(100, 50);
root.getChildren().add(ball);
root.getChildren().add(canvas);
s.setScene(scene);
s.setTitle("Bounce");
s.show();
setup();
Timeline timeline = new Timeline(new KeyFrame(Duration.millis(20), new EventHandler<ActionEvent>() {
// Change millis for speed of the ball
double dx = 7;
double dy = 3;
@Override
public void handle(ActionEvent t) {
// move the ball
ball.setLayoutX(ball.getLayoutX() + dx);
ball.setLayoutY(ball.getLayoutY() + dy);
//Make ball notice edge of screen and change direction.
}
}));
timeline.setCycleCount(Timeline.INDEFINITE);
timeline.play();
}
public static void main(String[] args) {
launch(args);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment