The world’s Largest Sharp Brain Virtual Experts Marketplace Just a click Away
Levels Tought:
Elementary,Middle School,High School,College,University,PHD
| Teaching Since: | Jul 2017 |
| Last Sign in: | 338 Weeks Ago, 1 Day Ago |
| Questions Answered: | 15833 |
| Tutorials Posted: | 15827 |
MBA,PHD, Juris Doctor
Strayer,Devery,Harvard University
Mar-1995 - Mar-2002
Manager Planning
WalMart
Mar-2001 - Feb-2009
Hello, I am currently working on an assignment as follows:
Code an application that prompt the user to enter an integer. The application will compute the factorial of the integer using recursion. This application must be supported by a GUI that implements major GUI elements (labels, text fields, buttons, event handlers, mouse handlers, etc.):
Your program must be very modular and you must code the needed validation (i.e. validating input).
This is what I have so far:
package factorial;
import javafx.application.Application;
import javafx.geometry.Insets;
import javafx.stage.Stage;
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.image.ImageView;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Pane;
import javafx.scene.text.Text;
public class Factorial extends Application {
protected Text text = new Text(50, 50, "Enter Integer");
protected BorderPane getPane() {
HBox paneForButtons = new HBox(20);
Button submit = new Button("Submit");
paneForButtons.getChildren().addAll(submit);
paneForButtons.setAlignment(Pos.CENTER);
paneForButtons.setStyle("-fx-border-color: green");
BorderPane pane = new BorderPane();
pane.setBottom(paneForButtons);
Pane numberText = new Pane();
numberText.getChildren().add(text);
pane.setCenter(numberText);
BorderPane numberField = new BorderPane();
numberField.setPadding(new Insets(5, 5, 5, 5));
numberField.setStyle("-fx-border-color: green");
numberField.setLeft(new Label("Number"));
TextField number = new TextField();
number.setAlignment(Pos.BOTTOM_RIGHT);
numberField.setCenter(number);
pane.setTop(numberField);
number.setOnAction(e -> text.setText(number.getText()));
Pane factorialText = new Pane();
factorialText.getChildren().add(text);
pane.setCenter(factorialText);
BorderPane factorialField = new BorderPane();
factorialField.setPadding(new Insets(5, 5, 5, 5));
factorialField.setStyle("-fx-border-color: green");
factorialField.setLeft(new Label("Factorial"));
TextField factorial = new TextField();
factorial.setAlignment(Pos.BOTTOM_RIGHT);
factorialField.setCenter(factorial);
pane.setBottom(factorialField);
// Set to non-editable(boolean error)factorialField.setEditable(false);//
factorial.setOnAction(e -> text.setText(factorial.getText()));
return pane;
}
@Override // Override the start method in the Application class
public void start(Stage primaryStage) {
Scene scene = new Scene(getPane(), 450, 200);
primaryStage.setTitle("Recursion");
primaryStage.setScene(scene);
primaryStage.show();
}
/**
* The main method is only needed for the IDE with limited
* JavaFX support. Not needed for running from the command line.
*/
public static void main(String[] args) {
launch(args);
}
}
----------- ----------- H-----------ell-----------o S-----------ir/-----------Mad-----------am ----------- Th-----------ank----------- yo-----------u f-----------or -----------you-----------r i-----------nte-----------res-----------t a-----------nd -----------buy-----------ing----------- my----------- po-----------ste-----------d s-----------olu-----------tio-----------n. -----------Ple-----------ase----------- pi-----------ng -----------me -----------on -----------cha-----------t I----------- am----------- on-----------lin-----------e o-----------r i-----------nbo-----------x m-----------e a----------- me-----------ssa-----------ge -----------I w-----------ill----------- be----------- qu-----------ick-----------ly