Question

In: Computer Science

very urgent !!! need it asap::::::::Write Java code which will create a GUI window on screen....

very urgent !!! need it asap::::::::Write Java code which will create a GUI window on screen. The window has one button: Doggy. When the user selects Doggy, “Bow Bow” should be printed on screen. Justify your syntax

Solutions

Expert Solution

package application;

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;

public class DoggyProgram extends Application {

        @Override
        public void start(Stage primaryStage) throws Exception {
         primaryStage.setTitle("Doggy Example!");       
         
         Label label = new Label();
         Button button1 = new Button("Doggy");
         
         button1.setOnAction(value -> {
                 label.setText("Bow Bow");
         });
         
         VBox hbox = new VBox(button1, label);

                label.setStyle
                (
                        "-fx-font-size:20px;"+
                    "-fx-padding:50px;"
                );
                
                Scene scene = new Scene(hbox, 200, 165);
                primaryStage.setScene(scene);
                primaryStage.show();
        }
         
        public static void main(String[] args) {
                launch(args);
        }
}
  • Any JavaFX Application can be created by extending to "javafx.application.Application" abstract class. and over-ride "start()" method within which actual coding is written.
  • "setTitle()" method is used to mention GUI component heading which should be called by using "Stage" class reference variable.
  • "Label" class object is used to mention the text which has to be displayed before and after user clicks button.
  • "Button" class object is used to create button on which user clicks based on the requirement. As an argument, we should pass "value" as an argument.
  • "setOnAction()" method is used to mention the code which has to be displayed after user clicks the button.
  • "setText()" method to replace the old text on label with new text.
  • "VBox" class object is used to align components in vertical column on top of each other. It is present in "javafx.scene.layout.VBox".
  • "setStyle()" method is used to provide CSS Styles for given component in GUI components.
  • "Scene" class object is used to project GUI components on the JavaFX Stage has to be visible.
  • "show()" method is used to show the complete GUI on the Output.

Related Solutions

URGENT!!!!!!!!!!!!!!!!!!! Write Java code which will create a GUI window on screen. The window has one...
URGENT!!!!!!!!!!!!!!!!!!! Write Java code which will create a GUI window on screen. The window has one button: Doggy. When the user selects Doggy, “Bow Bow” should be printed on screen. Justify your syntax.  
Write Java code which will create a GUI window on screen. The window has one button:...
Write Java code which will create a GUI window on screen. The window has one button: Doggy. When the user selects Doggy, “Bow Bow” should be printed on screen. Justify your syntax.
Write Java code which will create a GUI window on screen. The window has one button:...
Write Java code which will create a GUI window on screen. The window has one button: Doggy. When the user selects Doggy, “Bow Bow” should be printed on screen. Justify your syntax.
Write Java code which will create a GUI window on screen. The window has one button:...
Write Java code which will create a GUI window on screen. The window has one button: Doggy. When the user selects Doggy, “Bow Bow” should be printed on screen. Justify your syntax.
Write Java code which will create a GUI window on screen. The window has one button:...
Write Java code which will create a GUI window on screen. The window has one button: Doggy. When the user selects Doggy, “Bow Bow” should be printed on screen. Justify your syntax.
Write Java code which will create a GUI window on screen. The window has one button:...
Write Java code which will create a GUI window on screen. The window has one button: Doggy. When the user selects Doggy, “Bow Bow” should be printed on screen. Justify your syntax.
Write Java code which will create a GUI window on screen. The window has one button:...
Write Java code which will create a GUI window on screen. The window has one button: Doggy. When the user selects Doggy, “Bow Bow” should be printed on screen. Justify your syntax.
Write Java code which will create a GUI window on screen. The window has one button:...
Write Java code which will create a GUI window on screen. The window has one button: Doggy. When the user selects Doggy, “Bow Bow” should be printed on screen. Justify your syntax.
Write Java code which will create a GUI window on screen. The window has one button:...
Write Java code which will create a GUI window on screen. The window has one button: Doggy. When the user selects Doggy, “Bow Bow” should be printed on screen. Justify your syntax.  
Write Java code which will create a GUI window on screen. The window has one button:...
Write Java code which will create a GUI window on screen. The window has one button: Doggy. When the user selects Doggy, “Bow Bow” should be printed on screen. Justify your syntax. ASAP
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT