Java Modify this program and Add buttons for all the numbers in a calculator (0-9). Look at a calculator application to make sure you place the buttons correctly. Add buttons for addition, subtraction, multiplication and division. Add a button for the equal sign "=".
Java
Modify this program and
Add buttons for all the numbers in a calculator (0-9). Look at a calculator application to make sure you place the buttons correctly.
Add buttons for addition, subtraction, multiplication and division.
Add a button for the equal sign "=".
package myJavaFXpkg;
import javafx.application.Application;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.layout.Border;
import javafx.scene.layout.Pane;
import javafx.scene.text.Font;
import javafx.scene.text.FontPosture;
import javafx.scene.text.FontWeight;
import javafx.scene.text.TextAlignment;
import javafx.stage.Stage;
public class MyJavaFX extends Application
{
@Override // Override the start method in the Application class
public void start(Stage primaryStage) throws Exception
{
double sum = 45.6;
// Create a scene and place a button in the scene.
Pane pane = new Pane();
Button btOK = new Button("OK");
btOK.setLayoutX(20);
btOK.setLayoutY(80);
pane.getChildren().add(btOK);
Button SecondBtn = new Button("Second");
SecondBtn.setLayoutX(100);
SecondBtn.setLayoutY(80);
pane.getChildren().add(SecondBtn);
Label myLabel = new Label("123456");
myLabel.setFont(Font.font("Courier",FontWeight.BOLD,FontPosture.REGULAR,20));
myLabel.setStyle("-fx-border-color: blue;");
myLabel.setAlignment(Pos.BASELINE_RIGHT); // align text to the right side of the label.
myLabel.setLayoutX(10); // set the x location of the label
myLabel.setLayoutY(10); // set the y location of the label
myLabel.setPrefSize(250, 20); // set the width and height of the label
myLabel.setText("123456789"); // put some numbers into the label
pane.getChildren().add(myLabel);
myLabel.setText(Double.toString(sum));
Scene scene = new Scene(pane,280,300);
primaryStage.setTitle("MyJavaFX"); // Set the stage title
primaryStage.setScene(scene); // Place the scene in the stage
primaryStage.show(); // Display the stage
}
public static void main(String[] args)
{
launch(args);
}
}
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 1 images