Answer to Question #269763 in Java | JSP | JSF for nandi

Question #269763

Write a GUI that generates a multiplication or division table. A multiplication or division table is a useful tool for learning simple multiplication and division sums.


1
Expert's answer
2021-11-22T09:35:11-0500
import javafx.application.Application;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.layout.HBox;
import javafx.scene.layout.StackPane;
import javafx.scene.layout.VBox;
import javafx.scene.text.Font;
import javafx.stage.Stage;

public class Main extends Application {
    @Override
    public void start(Stage primaryStage) throws Exception {
        Label[] labels = new Label[9];
        VBox vBox = new VBox(50);
        vBox.setAlignment(Pos.CENTER);
        HBox[] rows = new HBox[3];
        for (int i = 0; i < rows.length; i++) {
            rows[i] = new HBox(50);
            rows[i].setAlignment(Pos.CENTER);
            vBox.getChildren().add(rows[i]);
        }
        for (int i = 0; i < labels.length; i++) {
            labels[i] = new Label("");
            labels[i].setFont(Font.font(16));
            rows[i / 3].getChildren().add(labels[i]);
        }
        for (int i = 1; i < 10; i++) {
            StringBuilder builder = new StringBuilder();
            for (int j = 1; j < 11; j++) {
                builder.append(i).append(" x ").append(j).append(" = ").append(i * j).append("\n");
            }
            labels[i - 1].setText(builder.toString());
        }
        primaryStage.setScene(new Scene(new StackPane(vBox),500,900));
        primaryStage.sizeToScene();
        primaryStage.setTitle("Multiplication Table");
        primaryStage.show();
    }

    public static void main(String[] args) {
        launch(args);
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS