PA4-1.pdf

Prof. Pitts CS585A: Practical Java Programming Spring 2019

Programming Assignment 4

Write your code as a class called CarSim which extends the JavaFX Application class. Submit your Java Source program through Canvas by the due date.

Part 1

For this assignment you are write a JavaFX application that duplicates the image below as closely as possible. The

main layout is a BorderPane, with the indicated layouts in each of the BorderPane's sections. There is no event handling code necessary for this assignment, only the start() method that builds the form.

Part 2

Your GUI will use a class called Car, which I'll provide. The Car class keeps the location (as (x,y) coordinates) and velocity of the car and allows you to get and set these properties. The Car class also has methods that calculates the distance

travel in a given time and calculates a new location for the car given the angle of travel (0 degrees is due east, 90 degrees is north, etc) and the time. In short, the GUI you created is a graphical front-end for the Car class.

1/2

Prof. Pitts CS585A: Practical Java Programming Spring 2019

Your assignment is to add actions to make the GUI work. Specifically, add the following actions and or property

bindings to your GUI framework:

• At the beginning of the start method create a new car. You can use the constructor call to match the intial values

you have in the X Coordinate, Y Coordinate, and Velocity input TextFields

• bind the value properties of the three slides to the text properties of the corresponding input TextFields

• Bind the text properties of the two input Time fields so that they both also show the save time value. Initial the time TextFields to 1.

• Initialized the Angle textField to 0 (due east).

• Use the setOnAction method of the Change X, Change Y, and Change Speed buttons to add an ActionEvent

handler that calls the Car set methods setX, setY, and setVelocity, respectively to change the properties of the Car object

• Use the setOnAction method of the Race Car button to add an ActionEvent handler that calls the Car distance and location methods with the double value equivalents of the text values in the Time and Angle TextFields. Set the

Distance and the New X Coordinate and New Y Coordinate TextField with the results. Draw the line in the center pane that show the path taken (remember you'll have to convert from normal x,y coordinates to Java's x,y

coordinates).

• Use the setOnAction method of the Clear All button to add an ActionEvent handler that clears the output

TextFields Distance and the New X Coordinate and New Y Coordinate.

• Use the setOnAction method of the Quit button to add and ActionEvent handler that quits the program. Use

Platform.exit() method.

2/2

  • Part 1
  • Part 2