Help with JavaFX By using this program: import javafx.application.*; import java
ID: 3687041 • Letter: H
Question
Help with JavaFX
By using this program:
import javafx.application.*;
import javafx.scene.*;
import javafx.stage.*;
import javafx.scene.layout.*;
import javafx.scene.control.*;
import javafx.event.*;
import javafx.geometry.*;
public class TextFieldDemo extends Application {
TextField tf;
Label response;
Button btnGetText;
public static void main(String[] args) {
launch(args);
}
public void start(Stage myStage) {
myStage.setTitle("TextField Demo");
FlowPane rootNode = new FlowPane(10,10);
// Center the controls in the scene
rootNode.setAlignment(Pos.CENTER);
// Create a scene
Scene myScene = new Scene(rootNode, 230, 140);
// Set the scene on the stage.
myStage.setScene(myScene);
// Create a label that will display the string
response = new Label("You entered: ");
// Create a button that gets the text.
btnGetText = new Button("Get String");
// Create a text field
tf = new TextField();
// Set the prompt
tf.setPromptText("Enter a String");
// Set the preferred column count
tf.setPrefColumnCount(15);
// when ENTER is pressed
tf.setOnAction(new EventHandler() {
public void handle(ActionEvent ae) {
response.setText("You entered: " + tf.getText());
}
});
// get text when button is pressed
btnGetText.setOnAction(new EventHandler() {
public void handle(ActionEvent ae) {
response.setText("You entered: " + tf.getText());
}
});
// Use a separator to better organize the layout.
Separator separator = new Separator();
separator.setPrefWidth(200);
// Add controls to the scene graph.
rootNode.getChildren().addAll(tf, btnGetText, separator, response);
// Show the stage and its scene.
myStage.show();
}
}
Explanation / Answer
Hi below i have given an sample method alone for a JavaFX that displays a temperature in both Celsius and Fahrenheit using the conversion formula in a binding expression for the Fahrenheit label for your reference,
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.