Question: * * * JavaFX * * * I am trying to make the image bounce around the pane indefinitely, all I can get it to
JavaFX I am trying to make the image bounce around the pane indefinitely, all I can get it to do is either shake or fly off the screen. Help!
import java.ioFileInputStream;
import java.ioFileNotFoundException;
import java.ioInputStream;
import javafx.animation.KeyFrame;
import javafx.animation.Timeline;
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.scene.layout.Pane;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.util.Duration;
public class JthomasMA extends Application
@Override
public void startStage primaryStage throws FileNotFoundException
InputStream catGraphic new FileInputStreamsrcGraphicsBlackCat.png;
Image cat new ImagecatGraphic;
ImageView viewableCat new ImageViewcat;
viewableCat.setFitHeight;
viewableCat.setFitWidth;
viewableCat.setX;
viewableCat.setY;
Pane pane new Pane;
pane.getChildrenaddviewableCat;
Timeline animation new Timelinenew KeyFrameDurationmillis new EventHandler
double dx dy ;
@Override
public void handleActionEvent e
viewableCat.setXviewableCatgetX dx;
viewableCat.setYviewableCatgetYdy;
ifviewableCatgetFitWidth pane.getWidth
dx ;
ifviewableCatgetFitHeight pane.getHeight
dy ;
viewableCat.setXdx;
viewableCat.setYdy;
;
animation.setCycleCountTimelineINDEFINITE;
animation.play;
Scene scene new Scenepane;
primaryStage.setTitleBouncing Cat";
primaryStage.setScenescene;
primaryStage.show;
public static void mainString args
launchargs;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
