Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hi ! Need help converting this code into GUI. It should have one textfield for user input ( ex 1234) , and one for displaying

Hi ! Need help converting this code into GUI. It should have one textfield for user input ( ex 1234) , and one for displaying the reversed number ( as Int). Aswell as adding a button("Reverse") to reverse the input number and to display it in second textfield. The recursive method in the GUI program should have the following signature public int reverseInteger(int value) , and validate input is a positive integer. The layout should be like this :image text in transcribed

Below is the code I need to be "converted" to GUI type code, as well as an attempt for the GUI code, and the layout for buttons,textfields etc. I am having trouble implementing the reverseInteger code into GUI.

public static void main(String[] args) {

Scanner input = new Scanner(System.in);// Create scanner for input

System.out.print("Enter integer to be reversed,please,Sir: ");

int number = input.nextInt();

System.out.print("The reversed number is ");

// Instanceof

ReverseIntFirst inst = new ReverseIntFirst();

inst.reverseInteger(number);

}

public void reverseInteger(int value) {

if (value != 0) { // Basis

System.out.print(value % 10);

value = value / 10;

reverseInteger(value); //Recursive

}

}

}

And here is my GUI Code:

public class ReversedInteger extends Application{

double paneWidth = 500;

double paneHeight = 250;

@Override

public void start(Stage primaryStage) {

// Textfield for entering user input, example 43223

TextField tfOrgNumber = new TextField();

tfOrgNumber.setPromptText("Enter number");

tfOrgNumber.getText();

// Textfield to display the reversed integer from user input

TextField tfRevNumber = new TextField();

tfRevNumber.setPromptText("Reversed number");

// Alignment for textfields

tfOrgNumber.setAlignment(Pos.BOTTOM_RIGHT);

tfRevNumber.setAlignment(Pos.BOTTOM_RIGHT);

// Create button

Button btReverse = new Button("Reverse");

// New pane, adding tf`s and bt

GridPane pane = new GridPane();

pane.setAlignment(Pos.CENTER);

pane.add(new Label("Your number"), 0, 0);

pane.add(tfOrgNumber, 1, 0);

pane.add(new Label("Your reversed number"), 0, 1);

pane.add(tfRevNumber, 1, 1);//*

pane.add(btReverse,1,2);

// Create a scene and place it in the stage

Scene scene = new Scene(pane, paneWidth, paneHeight);

primaryStage.setTitle("Reverse Integer"); // Set the stage title

primaryStage.setScene(scene); // Place the scene in the stage

primaryStage.show(); // Display the stage

// Eventhandler for button

btReverse.setOnAction( e-> }

/*public void reverseInteger(int value) { //

// I know i can use parseInt to fetch int from textfield , but not really how to do it.

if (value != 0) { // Basis

System.out.print(value % 10);

value = value / 10;

reverseInteger(value); //Recursive

}*/

// Integer.parseInt(tfOrgNumber.getText());

public static void main(String[] args) { // Main method

System.out.println("");

launch(args);

}}

Reverse Integer Your number Enter number Your reversed number Reversed number Reverse

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

International Baccalaureate Computer Science HL And SL Option A Databases Part I Basic Concepts

Authors: H Sarah Shakibi PhD

1st Edition

1542457084, 978-1542457088

More Books

Students also viewed these Databases questions

Question

List and explain the advantages of computer-aided NC programming?

Answered: 1 week ago

Question

Explain the various methods of job evaluation

Answered: 1 week ago

Question

Differentiate Personnel Management and Human Resource Management

Answered: 1 week ago

Question

Describe the functions of Human resource management

Answered: 1 week ago