Question

In: Computer Science

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

Solutions

Expert Solution

yes button can we can change text of a button and then that button can repeat action of the first button you can use the bellow code to do that.

import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.stage.Stage;

public class Main extends Application {
  public static void main(String[] args) {
    Application.launch(args);
  }

  @Override
  public void start(Stage primaryStage) {

    Button btn = new Button();
    final Label lbl = new Label();

    primaryStage.setTitle("Hello World!");

    lbl.setLayoutX(70);
    lbl.setLayoutY(150);

    btn.setLayoutX(100);
    btn.setLayoutY(100);
    btn.setText("Hello, World!");

    btn.setOnAction(new EventHandler<ActionEvent>() {

      @Override
      public void handle(ActionEvent event) {
        lbl.setText("Hello, World.");
      }
    });

    Group root = new Group();

    root.getChildren().add(btn);
    root.getChildren().add(lbl);
    primaryStage.setScene(new Scene(root, 300, 250));
    primaryStage.show();
  }
}

/////////////////////////////////////////////////////////////////////////////////////END ////////////////////////////////////////////////////////////////////////////////

# Feel free to like if my answer if it is worth helping to you.

# you can payback and help me with a like.


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...
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
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.
Can someone show me how to make this javaFx code work? The submit button should remain...
Can someone show me how to make this javaFx code work? The submit button should remain disabled until: ● There is text in all three fields. ● The two password fields have the same value. When Submit is clicked, display an Alert that says “Account Created!” When Quit is clicked, display an Alert that asks the user if they are sure they want to quit. If they click OK, quit the program with System.exit(0). If they click Cancel, the program...
Write a JavaFx program for addition of two numbers. (create text as Number1, Number2 and Result...
Write a JavaFx program for addition of two numbers. (create text as Number1, Number2 and Result and create 3 textfileds. Create sum button. You have to enter number1 and number2 in the textfileds. If you click the button Sum, the result will be showed in the third text field.
Use the Table button in the Rich-Text Editor to provide an adjacency matrix for a simple...
Use the Table button in the Rich-Text Editor to provide an adjacency matrix for a simple graph that meets the following requirements: 1) has 5 vertices 2) is maximal planar
javaScript html receives an entry of a character string in a text box, when a button...
javaScript html receives an entry of a character string in a text box, when a button is clicked, the count of vowels in the string stored in the textbox is displayed. The html file contains one function: vowelcount(). vowelcount(): returns the number of uppercase and lowercase English language vowel letter that occurs in the string entry in the textbox. //html: <!--    YOUR ID    YOUR NAME --> <html> <head> <script> function vowelcount() {        /* YOUR CODE HERE...
. List the steps that used to write the text and change text properties inside the...
. List the steps that used to write the text and change text properties inside the drawing object.
Chapter 8 Case Please submit this assignment as a Text Submission using the "Write Submission" button....
Chapter 8 Case Please submit this assignment as a Text Submission using the "Write Submission" button. Submissions attached as a separate file will not be graded! Englewood Company has an opportunity to produce and sell a revolutionary new smoke detector for homes. To determine whether this would be a profitable venture, the company has gathered the following data on probable costs and market potential: New equipment would have to be acquired to produce the smoke detector. The equipment would cost...
JAVAFX Create a JavaFx application that is an MP3 player. The size of the media player...
JAVAFX Create a JavaFx application that is an MP3 player. The size of the media player should be 800 pixels in width and 650 pixels in height. The media player should have a TextField that allows the user to type the full path of the .mp3 file to be played. The application should also use 2 Checkbox controls to show/hide the total playing time and the status (methods of MediaPlayer class). Use 2 RadioButton controls to change background colors (red...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT