1. [6 pts] Complete the following code so that it generates the following temperature converter GUI. Mark your answer with the relevant sub question's number clearly. Temperature Temperature Converter Farenhet 35.5 Celcius 29.72 Temperature Temperature Converter Farenheit 104.00 Celcius 40 Temperature Temperature Converter Farenheit Celcius Convert Convert Cher Convert Clear Fig 1: Enter Faren. press "Convert" Fig 2: Enter Celcius. press "Convert" Fig 3: press "Clear" import javafx.scene.control. * import javafx.scene.layout.StackPane; import javafx.scene.layoutGridPane; import javafx.scene.layout.HBox; import javafx.geometry.Insets; import javafx.geometry.Pos; import javafx.event.ActionEvent; import javafx.event. EventHandler; import java.text.DecimalFormat; public class TempConverter extends GridPane { private Label instruction, farenLabel, celciusLabel; private TextField tfFaren, tfCelcius; private Button convertBtn, clearBtn; //Constructor public Temp Converter() { // Step #1: instantiate all instance variables 1/Step #1: instantiate all instance variables instruction = new Label("Temperature Converter"); farenLabel = new Label("Farenheit"); celciusLabel = new Label("Celcius"); tffaren = new TextField(); tfCelcius = new TextField; convertBtn = new Button("Convert); clearBtn = new Button("Clear"); //Create a GridPane and set its properties GridPane gridPane = new GridPane(); gridPane.setAlignment(Pos.CENTER); gridPane.setPadding(new Insets(12, 12, 12, 12)); gridPane.setHgap(5); gridPane.setVgap(5): 1/(01.1) add labels and text fields inside gridPane //Create a HBox which contains the two buttons HBox buttonPane = new HBox(15); buttonPane.setPadding(new Insets(12, 12, 12, 12)); buttonPane.setAlignment(Pos.CENTER); //(Q1.2) add two buttons inside buttonPane 1/(Q1.3)TempConverter is a GridPane. Add the relevant GUI component //(01.4) register the source object with a new handler object }//end of the constructor //step #2: The handler class private class TempHandler implements EventHandler
{ public void handle(ActionEvent e) public void handle(ActionEvent e) { double farenNum, celciusNum; DecimalFormat fmt = new DecimalFormat("0.00"); //Check which button is picked Object source = e.getSource(); if( source == convertBtn && !tfFaren.getText().trim().isEmpty() && tfCelcius.getText().trim().isEmpty() { //(Q1.5) handle this case here } else if( source == convertBtn && tffaren.getText().trim().isEmpty !tfCelcius.getText().trim().isEmpty) { //(Q1.6) handle this case here } else if(source == clearBtn) { //(Q1.7) handle this case here 3 else //do nothing for all other cases && }//end of handle() }//end of TempHandler class ******* [/The following is the driver program for TempConverter import javafx.application. Application; import javafx.scene.Scene; import javafx.stage.Stage; import javafx.scene.layout.StackPane; ****** //The following is the driver program for TempConverter import javafx.application.Application; import javafx.scene.Scene; import javafx.stage.Stage; import javafx.scene.layout.StackPane; public class Temperature GUI extends Application { public void start(Stage primaryStage) { // create a TempConverter pane TempConverter gui = new TempConverter(); StackPane rootPane = new StackPane(); rootPane.getChildren().add(gui); // Create a scene and place rootPane in the stage Scene scene = new Scene(rootPane, 250, 180); primaryStage.setTitle("Temperature Converter"); primaryStage.setScene(scene); primaryStage showO; } } 1. [6 pts] Complete the following code so that it generates the following temperature converter GUI. Mark your answer with the relevant sub question's number clearly. Temperature Temperature Converter Farenhet 35.5 Celcius 29.72 Temperature Temperature Converter Farenheit 104.00 Celcius 40 Temperature Temperature Converter Farenheit Celcius Convert Convert Cher Convert Clear Fig 1: Enter Faren. press "Convert" Fig 2: Enter Celcius. press "Convert" Fig 3: press "Clear" import javafx.scene.control. * import javafx.scene.layout.StackPane; import javafx.scene.layoutGridPane; import javafx.scene.layout.HBox; import javafx.geometry.Insets; import javafx.geometry.Pos; import javafx.event.ActionEvent; import javafx.event. EventHandler; import java.text.DecimalFormat; public class TempConverter extends GridPane { private Label instruction, farenLabel, celciusLabel; private TextField tfFaren, tfCelcius; private Button convertBtn, clearBtn; //Constructor public Temp Converter() { // Step #1: instantiate all instance variables 1/Step #1: instantiate all instance variables instruction = new Label("Temperature Converter"); farenLabel = new Label("Farenheit"); celciusLabel = new Label("Celcius"); tffaren = new TextField(); tfCelcius = new TextField; convertBtn = new Button("Convert); clearBtn = new Button("Clear"); //Create a GridPane and set its properties GridPane gridPane = new GridPane(); gridPane.setAlignment(Pos.CENTER); gridPane.setPadding(new Insets(12, 12, 12, 12)); gridPane.setHgap(5); gridPane.setVgap(5): 1/(01.1) add labels and text fields inside gridPane //Create a HBox which contains the two buttons HBox buttonPane = new HBox(15); buttonPane.setPadding(new Insets(12, 12, 12, 12)); buttonPane.setAlignment(Pos.CENTER); //(Q1.2) add two buttons inside buttonPane 1/(Q1.3)TempConverter is a GridPane. Add the relevant GUI component //(01.4) register the source object with a new handler object }//end of the constructor //step #2: The handler class private class TempHandler implements EventHandler { public void handle(ActionEvent e) public void handle(ActionEvent e) { double farenNum, celciusNum; DecimalFormat fmt = new DecimalFormat("0.00"); //Check which button is picked Object source = e.getSource(); if( source == convertBtn && !tfFaren.getText().trim().isEmpty() && tfCelcius.getText().trim().isEmpty() { //(Q1.5) handle this case here } else if( source == convertBtn && tffaren.getText().trim().isEmpty !tfCelcius.getText().trim().isEmpty) { //(Q1.6) handle this case here } else if(source == clearBtn) { //(Q1.7) handle this case here 3 else //do nothing for all other cases && }//end of handle() }//end of TempHandler class ******* [/The following is the driver program for TempConverter import javafx.application. Application; import javafx.scene.Scene; import javafx.stage.Stage; import javafx.scene.layout.StackPane; ****** //The following is the driver program for TempConverter import javafx.application.Application; import javafx.scene.Scene; import javafx.stage.Stage; import javafx.scene.layout.StackPane; public class Temperature GUI extends Application { public void start(Stage primaryStage) { // create a TempConverter pane TempConverter gui = new TempConverter(); StackPane rootPane = new StackPane(); rootPane.getChildren().add(gui); // Create a scene and place rootPane in the stage Scene scene = new Scene(rootPane, 250, 180); primaryStage.setTitle("Temperature Converter"); primaryStage.setScene(scene); primaryStage showO; } }