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

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.
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...
What is property binding in JavaFX?
What is property binding in JavaFX?
Apply JavaFX and exception handling to design a CircleApp class using proper JavaFX GUI components, such...
Apply JavaFX and exception handling to design a CircleApp class using proper JavaFX GUI components, such as labels, text fields and buttons(Submit, Clear, and Exit) to compute the area of circle and display the radius user entered in the text field and computing result in a proper location in the application windows. It will also verify invalid data entries for radius(No letters and must be a postive real number) using expection handling. Your code will also have a custom-designed exception...
Using the data in the appendix of text, calculate the standard enthalpy change for each of...
Using the data in the appendix of text, calculate the standard enthalpy change for each of the following reactions: (A)   Si(s) + 2F2(g) ⟶ SiF4(g) (B)    2C(s) + 2H2(g) + O2(g) ⟶   CH3CO2H(l) (C)    CH4(g) + N2(g) ⟶   HCN(g) + NH3(g) (D)   CS2(g) + 3Cl2(g) ⟶ CCl4(g) + S2Cl2(g)
Using the date in the appendix of text, calculate the standard enthalpy change for each of...
Using the date in the appendix of text, calculate the standard enthalpy change for each of the following reaction. (A) Si (s) + 2F2(g) -------- SiF4 (g) (B) 2C(s) + 2H2(g) -------- CH3CO2 H(i) (C) CH4(g) + N2 (g) -------- HCN (g)+ NH3 (g) (D) CS2 (g) + 3Cl2 (g) ------ CCl4 (g) + S2 Cl2 (g0
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT