Question

In Java. JavaFX where you use a spinner to pick a number option 1-8 and then...

In Java. JavaFX where you use a spinner to pick a number option 1-8 and then display the text version of that number under it. You will need a string spinner and a text object for sure. Thank you in advance
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Here is the completed code for this problem. Comments are included, go through it, learn how things work and let me know if you have any doubts or if you need anything to change. If you are satisfied with the solution, please rate the answer. Thanks

// SpinnerExample.java

import javafx.application.Application;

import static javafx.application.Application.launch;

import javafx.geometry.Pos;

import javafx.scene.Scene;

import javafx.scene.control.Spinner;

import javafx.scene.layout.Pane;

import javafx.scene.layout.VBox;

import javafx.scene.text.Text;

import javafx.stage.Stage;

public class SpinnerExample extends Application {

    //a spinner object to display the numbers

    Spinner<Integer> spinner;

    //Text object to display the text value of the number

    Text text;

    //string array to store word representation of each number

    String stringValues[] = {"one", "two", "three", "four", "five", "six", "seven", "eight"};

    @Override

    public void start(Stage primaryStage) {

        //initializing a spinner that shows values from 1 to 8, with 1 being initial value

        spinner = new Spinner<Integer>(1, 8, 1);

        //adding listener to spinner to call update method when changed

        spinner.valueProperty().addListener(e -> update());

        //initializing the text field with value of 1 (one)

        text = new Text(stringValues[0]);

       

        //creating a Vbox to arrange elements, setting alignment and spacing, and initializing a scene

        VBox root = new VBox(spinner, text);

        root.setAlignment(Pos.CENTER);

        root.setSpacing(20);

        Scene scene = new Scene(root, 300, 100);

        primaryStage.setScene(scene);

        primaryStage.setTitle("Spinner");

        primaryStage.show();

    }

   

    //handler method

    public void update() {

        //getting value from spinner

        int value = spinner.getValue();

        //using value-1 as index of equivalent word from stringValues

        text.setText(stringValues[value - 1]);

    }

    public static void main(String[] args) {

        launch(args);

    }

}

/*OUTPUT*/

Add a comment
Know the answer?
Add Answer to:
In Java. JavaFX where you use a spinner to pick a number option 1-8 and then...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • For this question you will need to complete the methods to create a JavaFX GUI application...

    For this question you will need to complete the methods to create a JavaFX GUI application that implements two String analysis algorithms. Each algorithm is activated when its associated button is pressed. They both take their input from the text typed by the user in a TextField and they both display their output via a Text component at the bottom of the GUI, which is initialized to “Choose a string methods as indicated in the partially completed class shown after...

  • I need the following written in Java please, thank you ' We want you to implement...

    I need the following written in Java please, thank you ' We want you to implement a java class that will show details on users and throw exceptions where needed. The following requirements specify what fields you are expected to implement in your User class: - A private String firstName that specifies the first name of the user - A private String lastName that specifies the last name of the user - A private int age that specifies user's age...

  • please answer correctly and follow the code structure given [JavaFX/ Exception handing and text I/O] 1....

    please answer correctly and follow the code structure given [JavaFX/ Exception handing and text I/O] 1. Write a program for the following. NOTE that some of these steps are not dependent on each other. Using methods is mandatory. Make sure to use methods where it makes sense. a. Ask the user for a series of integers entered from the keyboard. Use a sentinel value such as 999 to end the input process. If the entered values are not integers, throw...

  • Pick one type of contract from a supply chain/logistics and defend the use of that option based o...

    Pick one type of contract from a supply chain/logistics and defend the use of that option based on the contractual relationship between the two parties of sampled transaction. Need various reasons as to why you think that contract is the best and if it could be at least one page. Thank you in advance! Example:Long-Term Contract, Portfolio Contract, Advance Purchase Contract, Pay-Back Contract, Cost-Sharing Contract, Buy-Back Contract, Revenue-Sharing Contract, Quantity-Flexibility Contract, Sales Rebate Contract etc.

  • language is java Restrictions: You are not allowed to use anything from the String, StringBuilder, or...

    language is java Restrictions: You are not allowed to use anything from the String, StringBuilder, or Wrapper classes. In general, you may not use anything from any other Java classes, unless otherwise specified. You are not allowed to use String literals in your code ("this is a string literal"). You are not allowed to use String objects in your code. The methods must be implemented by manipulating the data field array, The CSString Class: NOTE: Pay very careful attention to...

  • Create a JavaFX game: Guess the Number create a random # between 1 and 1000 Ask...

    Create a JavaFX game: Guess the Number create a random # between 1 and 1000 Ask user for a guess; possible answers TOO LOW TOO HIGH WINNER! print guess to screen if the user wins, write the random number, and all the guesses to a file. If the user doesn't guess in 10 turns, display the number. NOTES: You may want to implement: Restart option Best Guess statistic (game 1 took 8 tries, game 2 took 5 - 5 is...

  • Write a JavaFX program to display 5 labels and 3 buttons. You can use any kind...

    Write a JavaFX program to display 5 labels and 3 buttons. You can use any kind of Pane you like to use. Display 3 red circles and 2 blue rectangles (pick your own size). Use the Image and ImageView classes (explained in section 14.9 of your textbook) to show 2 images of your choice. Include your first and last name somewhere on the frame, label, button, etc. We won’t discuss handing events where one would be able to click buttons...

  • you need to use javafx for following problem these instructions is for JavaFX program so you...

    you need to use javafx for following problem these instructions is for JavaFX program so you need to follow the instructions and according to images you have design the GUI Write a program to design the following interface and use event handling and File 10 to perform the given operation. Make sure you have a background image and different color for labels and buttons for this interface. Input Information Course Quiz Grade Assignment Grade Fal Grade Submit View Grade Info...

  • public static void main(String[] args) { int option=0;    while(option<8){ Scanner input=new Scanner(System.in); System.out.println("Welcome! Please enter...

    public static void main(String[] args) { int option=0;    while(option<8){ Scanner input=new Scanner(System.in); System.out.println("Welcome! Please enter your name"); String name=input.next(); Person user= new Person(name); System.out.println("Your id: "+user.getID()); System.out.println("Login successful"); System.out.println("------------------------------"); while(option!=7){ System.out.println("1.Create and host a new meeting"); System.out.println("2.Cancel a meeting"); System.out.println("3.Attend an existing meeting"); System.out.println("4.Leave a meeting"); System.out.println("5.Display my meetings"); System.out.println("6.Display meetings organized by me"); System.out.println("7.Logout"); System.out.println("8.Exit the app");    option=input.nextInt(); switch(option){ case 1: break; case 2: break; case 3: break; case 4: break; case 5: break; case 6: break;...

  • Java Programming Assignment (JavaFX required). You will modify the SudokuCheckApplication program that is listed below. Start...

    Java Programming Assignment (JavaFX required). You will modify the SudokuCheckApplication program that is listed below. Start with the bolded comment section in the code below. Create a class that will take string input and process it as a multidimensional array You will modify the program to use a multi-dimensional array to check the input text. SudokuCheckApplication.java import javafx.application.*; import javafx.event.*; import javafx.geometry.*; import javafx.scene.*; import javafx.scene.control.*; import javafx.scene.layout.*; import javafx.stage.*; public class SudokuCheckApplication extends Application { public void start(Stage primaryStage)...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT