Question

In: Computer Science

A JavaFX question a method called generate2Num(Pane, pane){}; A botton "botton1" that botton.setOnAction(e-> {}); calling generate2Num...

A JavaFX question

a method called generate2Num(Pane, pane){};

A botton "botton1" that botton.setOnAction(e-> {}); calling generate2Num method and show the numbers on Scene.

Every time the user clicks botton1, the updated number will show on the Scene.

I just wanna know how can I update my data by click the button.

Please show the code , thank you

Solutions

Expert Solution

Answer:-

************Main.java************

package application;
  
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.Pane;
import javafx.scene.text.Text;
import javafx.stage.Stage;


public class Main extends Application {
   @Override
   public void start(Stage primaryStage) {
       try {
           BorderPane root = new BorderPane();
           Button button1 = new Button("updatenumber");
             
          
   // action event
   EventHandler<ActionEvent> event = new EventHandler<ActionEvent>() {
   public void handle(ActionEvent e)
   {
  
       generate2Num(root);
   }
   };
  
   // when button is pressed
   button1.setOnAction(event);
           root.setTop(button1);
           Scene scene = new Scene(root,400,400);
           scene.getStylesheets().add(getClass().getResource("application.css").toExternalForm());
           primaryStage.setScene(scene);
           primaryStage.show();
       } catch(Exception e) {
           e.printStackTrace();
       }
   }
  
   int number=0;
public void generate2Num(Pane pane){
   number++;
   BorderPane borderp= (BorderPane) pane;
   borderp.setCenter(new Text(""+number));
  
}
  
   public static void main(String[] args) {
       launch(args);
   }
}
************Main.java Output************

Description:-in the above example "i clicked the updatenumber button 80 times" the updated number is "80"

whenever you click on the "updatenumber" button  the updated number will show on the Scene

***Please Hit The Like Button***


Related Solutions

L4 (0.4 marks) Code a calling and called method that tries to demonstrate that a called...
L4 (0.4 marks) Code a calling and called method that tries to demonstrate that a called method cannot remember how many times it has been called if it’s limited to only using its formal parameters and local variables. For technical reasons this cannot be demonstrated. You will discover why in your attempt. Now use a class-level variable to do the job properly.
Method calling in c# I need to write methods for calling the min and max numbers...
Method calling in c# I need to write methods for calling the min and max numbers using this code; Console.WriteLine("Calling highest method."); Console.WriteLine("Highest number is: {0}", highest(3)); Console.WriteLine("Calling lowest method."); Console.WriteLine("Lowest number is: {0}", lowest(3));
Develop a JavaFX GUI application called Registration that implements a user interface for registering for a...
Develop a JavaFX GUI application called Registration that implements a user interface for registering for a web site. The application should have labeled text fields for the Full Name, User Name, Password, Student Id, and a TextAreafor About Me. Include a button labeled Send. When the Send button is clicked, your program should print the contents of all fields (with labels) to standard output using println()statements.
The ( ) method will be called if a method is called from within a subclass...
The ( ) method will be called if a method is called from within a subclass that overrides a super class method. In Java the (          ) keyword is used to prevent changes being made to a variable. The property of ( ) refers to the ability of an object to take on many forms. In Java, a character constant’s value is its integer value in the ( ) character set. An interface requires each of the interface’s methods to...
Question 17 (1 point) What is the return type of this method? public <E extends Comparable<E>>...
Question 17 (1 point) What is the return type of this method? public <E extends Comparable<E>> int theMethod(E arg) Question 17 options: E Comparable int arg Question 18 (1 point) What is the primary benefit of writing generic classes and methods? Question 18 options: Generic classes and methods are more type-safe Generic classes and methods are shorter Generic classes and methods are faster Generic classes and methods are backwards compatible Question 19 (1 point) What is wrong with the following...
Write a method that returns the result when the calling object is multiplied by a scalar...
Write a method that returns the result when the calling object is multiplied by a scalar value. For example, the PolyTerm 2.4x^3 multiplied by -1.2 should return the PolyTerm object representing -2.88x^3. Language: Java. Method name be like: scalarMultiply(double) Some Outputs: Test 1: Coefficient =1, Exponent = 1 scalarMultiply(1.2).coefficient return 1.2; scalarMultiply(1.2).exponent returns 1. Test 2: Coefficient =2.4, Exponent = 3 scalarMultiply(-1.2).coefficient returns -2.88 scalarMultiply(-1.2).exponent return 3 Test 3: Coefficient =-1.5 Exponent = 0 scalarMultiply(0).coefficient returns 0 scalarMultiply(0).exponent returns 3...
in java What object is passed to the start method in a JavaFX program? What should...
in java What object is passed to the start method in a JavaFX program? What should you do with it?
An element e of a ring is called an idempotent if e^2 = e. Find a...
An element e of a ring is called an idempotent if e^2 = e. Find a nontrivial idempotent e in the ring Z143.
A JavaFX UI class has a button named 'btnOk' that needs to call a void method...
A JavaFX UI class has a button named 'btnOk' that needs to call a void method with no parameters named 'displayResults' when it is clicked. Write the complete lambda-expression statement to set up the btnOk event handler to do this.
1.Create a standard Java project (i.e. not a JavaFX project) in NetBeans called Personsages 2.Declare a...
1.Create a standard Java project (i.e. not a JavaFX project) in NetBeans called Personsages 2.Declare a Scanner variable called keyboardInput and a variable called personAge as type int. Code the statement to read in an integer with a prompt to "Enter your age as an integer:". 3.Code an "if/else if" (also called a multi-way if) block to output the following text based on age ranges personAge might contain: 0 through 12: Person is a pre-teen. 13 through 19: Person is...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT