Question

In: Computer Science

Java Write a JavaFX application that displays a button and a number. Every time the button...

Java

Write a JavaFX application that displays a button and
a number. Every time the button is pushed, change the number
to a random value between 1 and 100.

Thank you and can you show a picture of the result as well

Solutions

Expert Solution

import java.util.Random;
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.layout.Pane;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;

public class DisplayRandom extends Application {
  
@Override
public void start(Stage primaryStage) {
Button btn = new Button("Generate Random");
Random rand = new Random();
int num = rand.nextInt((100-1)+1)+1;
Label l1 = new Label(""+num);
btn.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
l1.setText("");
int num = rand.nextInt((100-1)+1)+1;
l1.setText(""+num);

}
});
  
Pane root = new Pane();
btn.setLayoutX(100);
btn.setLayoutY(100);
l1.setLayoutX(150);
l1.setLayoutY(50);
root.getChildren().add(btn);
root.getChildren().add(l1);
  
Scene scene = new Scene(root, 300, 250);
  
primaryStage.setTitle("Generate Random");
primaryStage.setScene(scene);
primaryStage.show();
}

/**
* @param args the command line arguments
*/
public static void main(String[] args) {
launch(args);
}
  
}

/* OUTPUT */


Related Solutions

Write a JavaFX application that presents a button and a circle. Every time the button is...
Write a JavaFX application that presents a button and a circle. Every time the button is pushed, the circle should be moved to a new random location within the window. This must only be one .java file. I cannot use import javafx.geometry.Insets; import javafx.scene.canvas.Canvas; import javafx.scene.canvas.GraphicsContext; import javafx.scene.layout.HBox; This is what I have so far: import javafx.application.Application; import javafx.event.ActionEvent; import javafx.event.EventHandler; import javafx.geometry.Pos; import javafx.scene.Group; import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.shape.Circle; import javafx.scene.paint.Color; import javafx.stage.Stage; public class CircleJumper extends Application...
Write a Java application that inputs an unknown number of employees and determines and displays the...
Write a Java application that inputs an unknown number of employees and determines and displays the gross pay for each employ. The company pays straight time for the first 40 hours worked by each employee (hours times rate), and straight time plus time-and-a-half for all hours worked in excess of 40 hours. Input the number of hours worked and hourly rate for each of the employees, then determine and display the employee’s gross pay. At the end of the program,...
Write a JavaFX application that displays a Label containing the opening sentence or two from your...
Write a JavaFX application that displays a Label containing the opening sentence or two from your favorite book. Save the project as FXBookQuote1a. Add a button to the frame in the FXBookQuote program. When the user clicks the button, display the title of the book that contains the quote in a second label. Save the project as FXBookQuote1b // FXBookQuote1a.java import javafx.application.Application; import static javafx.application.Application.launch; import javafx.geometry.Insets; import javafx.scene.Scene; import javafx.scene.control.Label; import javafx.scene.layout.Pane; import javafx.scene.text.Font; import javafx.stage.Stage; public class FXBookQuote1a...
In C# Please Write an application named Perfect that displays every perfect number from 1 through...
In C# Please Write an application named Perfect that displays every perfect number from 1 through 10,000. A number is perfect if it equals the sum of all the smaller positive integers that divide evenly into it. For example, 6 is perfect because 1, 2, and 3 divide evenly into it and their sum is 6. Starting code. using static System.Console; class Perfect { static void Main() { // Write your main here. } }
In Java and using JavaFX, write a client/server application with two parts, a server and a...
In Java and using JavaFX, write a client/server application with two parts, a server and a client. Have the client send the server a request to compute whether a number that the user provided is prime. The server responds with yes or no, then the client displays the answer.
javaFX is there a way to change the text of a button and then that button...
javaFX is there a way to change the text of a button and then that button repeats to actions of the first button
Write an application named DisplayMultiplicationTable that displays a table of the products of every combination of...
Write an application named DisplayMultiplicationTable that displays a table of the products of every combination of two integers from 1 through 10 Beginning Code. Please answer in C# using static System.Console; class DisplayMultiplicationTable { static void Main() { // Write your main here. } } }
Write a JavaFX application that presents two buttons and a number (initially 50) to the user....
Write a JavaFX application that presents two buttons and a number (initially 50) to the user. Label the buttons Increment and Decrement. When the increment button is pushed, increment the displayed value. Likewise, decrement the value when the decrement button is pushed. This has to use Java.Fx and not Java.Awt
In Java, Write a JavaFX application that draws multiple circles using a rubberbanding technique. The circle...
In Java, Write a JavaFX application that draws multiple circles using a rubberbanding technique. The circle size is determined by a mouse drag. Use the initial mouse press location as the fixed center point of the circle. Compute the distance between the current location of the mouse pointer and the center point to determine the current radius of the circle.Thank you and could you also show the finished product?
in java Write a program that reads in ten numbers and displays the number of distinct...
in java Write a program that reads in ten numbers and displays the number of distinct numbers and the distinct numbers separated by exactly one space (i.e., if a number appears multiple times, it is displayed only once). (Hint: Read a number and store it to an array if it is new. If the number is already in the array, ignore it.) After the input, the array contains the distinct numbers. Here is the sample run of the program: Enter...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT