Question: Create a GUI in java that converts between Fahrenheit and Celcius Antemperatures. GUI should look like this: If I enter a number in the Fahr

Create a GUI in java that converts between Fahrenheit and Celcius Antemperatures. GUI should look like this: If I enter a number in the Fahr box, click F -> C, the Centigrade is displayed. If I enter a value in Cent, the Fahrenheit is displayed when clicking C -F. So the boxes represent both inputs and outputs depending on the button clicked. If a box is clicked and no proper value is in the ionput box, an Error should be displayed. Do the conversion logic in a separate "business logic" class. The class called "TemperatureConversion" should just have 1 private field. It should provide the following methods: toCentigrade() toFahrenheit() getValue() No setters are necessary and have only one constructor. The internal field would take on different meanings depending on whether toCentigrade or toFahrenheit is called. If toCentigrade is called, then assume the internal value is in Fahrenheit. If toFanhrenheit is called, assume the value in in Centigrade. The getValue just returns the internal field. Use this javafx codegui for a quadratic equation as an example:import javafx.application.Application; import javafx.geometry.Insets; import javafx.geometry.Pos; import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.control.Label; import javafx.scene.control.TextField; import javafx.scene.layout.HBox; import javafx.scene.layout.VBox; import javafx.stage.Stage; public class QuadraticGUIApp extends Application { private TextField createClearableTextField(){ var textField = new TextField(); textField.setPrefWidth(100); // Set a fixed width // Add mouse pressed event handler to clear the text textField.setOnMousePressed(event -> textField.clear()); return textField; } private TextField createReadOnlyTextField(){ var textField = new TextField(); textField.setPrefWidth(100); textField.setEditable(false); textField.setFocusTraversable(false); textField.setMouseTransparent(true); return textField; } private void calculateRoots(TextField tfA, TextField tfB, TextField tfC, TextField tfRoot1, TextField tfRoot2){ try { var a = Double.parseDouble(tfA.getText().trim()); var b = Double.parseDouble(tfB.getText().trim()); var c = Double.parseDouble(tfC.getText().trim()); var q = new Quadratic(a, b, c); var noOfRoots = q.noOfRoots(); if (noOfRoots ==2){ var r1= q.getRoot1(); var strRoot1= String.format("%.2f", r1); tfRoot1.setText(strRoot1); var r2= q.getRoot2(); var strRoot2= String.format("%.2f", r2); tfRoot2.setText(strRoot2); } else if (noOfRoots ==1){ var r1= q.getRoot1(); var strRoot1= String.format("%.2f", r1); tfRoot1.setText(strRoot1); } else { tfRoot1.setText("None"); tfRoot2.setText("None"); }} catch (RuntimeException ex){ tfRoot1.setText("Error"); tfRoot2.setText("Error"); }} private VBox buildGUI(){// Input TextFields var tfA = createClearableTextField(); var tfB = createClearableTextField(); var tfC = createClearableTextField(); // Output TextFields var tfRoot1= createReadOnlyTextField(); var tfRoot2= createReadOnlyTextField(); // Button for Calculation var calc = new Button("Calculate Roots"); calc.setOnAction(event -> calculateRoots(tfA, tfB, tfC, tfRoot1, tfRoot2)); var inputs = new HBox(10); inputs.setAlignment(Pos.CENTER); inputs.getChildren().addAll(new Label("A"), tfA, new Label("B"), tfB, new Label("C"), tfC); var controller = new HBox(10); controller.setPadding(new Insets(15)); controller.setAlignment(Pos.CENTER); controller.getChildren().add(calc); var outputs = new HBox(10); outputs.setAlignment(Pos.CENTER); outputs.getChildren().addAll(new Label("Root 1"), tfRoot1, new Label("Root 2"), tfRoot2); var gui = new VBox(15); gui.setAlignment(Pos.CENTER); gui.getChildren().addAll(inputs, controller, outputs); gui.setStyle("-fx-font-weight: bold;"); return gui; } @Override public void start(Stage primaryStage){ var gui = buildGUI(); var scene = new Scene(gui,500,200); primaryStage.setScene(scene); primaryStage.setTitle("Quadratic Equation Solver - Tony Silvestri"); primaryStage.setResizable(false); primaryStage.show(); } public static void main(String[] args){ Application.launch(args); }}
 Create a GUI in java that converts between Fahrenheit and Celcius

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!