Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

NetBeans for FX Java I nearly have the coding done, but I seem to be stuck. After clicking the button to create a vehicle, the

NetBeans for FX Java I nearly have the coding done, but I seem to be stuck. After clicking the button to create a vehicle, the next window never pops up. It should contain a list of the cities you can drive to, with an option to refuel. I still have to code the drive method; however I can't get to that point because the window doesn't pop up to begin with.

image text in transcribedimage text in transcribed

App.java Vehicle.java Location.java Lic class App extends Application \{ private ArrayList> locations = new ArrayList (); private Vehicle vehicle; public static void main(String[] args) \{ launch(strings:args) ; \} Qoverride public void start(Stage stage) \{ ListView locationsLV = new ListView(); locationsLV.getItems () .add (new Location (name: "Cleveland", w: 0, Y: 0, gasStation: true)); locationsLV.getItems () .add (new Location (name: "North Pole", w: 500, p: -100, gasStation: true)); locationsLV.getItems () .add (new Location (name: "Campbell Hill", w: 50,p:50, gasstation: false)) ; locationsLV.getItems () .add (new Location (name: "Tokyo", w: -100,r: 1000,gasstation: true)); locationsLV.getItems () .add (new Location (name: "Chicago", w: -200,y: 75,gasstation: true)); locationsLV.getItems () .add (new Location (name: "Erie PA", w: 150,7:0,gasstation: true)); locationsLV.getItems () .add (new Location (name: "Allegheny Nation Forrest", w 300,y: -75,gasstation: false)); Label infoLbl = new Label (); AnchorPane root = new AnchorPane (); Scene scene = new Scene (parent: root, d: 480, di:360); Label messageLbl = new Label(string: "Hello."); Label nameLbl = new Label (string: "Please create your vehicle"); Label mfcLbl = new Label(string: "What is your vehicle's Maximum Fuel Capacity: "); Label mpgLbl = new Label(string: "What is your vehicle's Miles Per Gallon: "); TextField mfctF = new TextField (); TextField mpgTF = new TextField (); Button createVehicleBtn = new Button(string: "Create Vehicle"); createVehicleBtn.setonAction(actionEvent \{ try{ double maxFuelCapacity = Double.parseDouble(s: mfcTF.getText ()); double mpg = Double.parseDouble (s: mpgTF.getText ()); if (maxFuelCapacity { try \{ infoLbl.setText (locationsLV.getSelectionModel (). getSelectedItem (). getName ()); \} catch (Exception e) \{ infoLbl.setText("Please select a location first."); \} locationLbl.setText ("Current Location: " + vehicle.getLocation().getName()); fuelLbl.setText ("Current Fuel: " + vehicle.getCf()); ) ; Button refuelBtn = new Button (string: "Refuel"); refuelBtn.setonAction (actionEvent >{ vehicle.refuel (); locationLbl.setText ("Current Location: " + vehicle.getLocation().getName()); fuelLbl.setText ("Current Fuel: " + vehicle.getCf()); ) ; AnchorPane.setTopAnchor (node: locationLbl, d: 20.0); AnchorPane.setLeftAnchor (node: locationLbl, d: 20.0); AnchorPane.setTopAnchor (node: fuelLbl, d: 40.0); AnchorPane.setLeftAnchor (node: fuelLbl, d: 20.0); AnchorPane.setBottomAnchor (node:driveBtn, d: 20.0); AnchorPane.setLeftAnchor (node: driveBtn, d: 20.0); AnchorPane.setBottomAnchor (node: refuelBtn, d:20.0); AnchorPane.setLeftAnchor(node: refuelBtn, d: 120.0); drivingPane.getChildren() .addAll (es: locationLbl, es: fuelLbl, es: driveBtn, es: refuelBtn); return drivingScene

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Intelligent Databases Object Oriented Deductive Hypermedia Technologies

Authors: Kamran Parsaye, Mark Chignell, Setrag Khoshafian, Harry Wong

1st Edition

0471503452, 978-0471503453

More Books

Students also viewed these Databases questions