Question

Can someone please comment this on what the javafx do and how they are implemented? import...

Can someone please comment this on what the javafx do and how they are implemented?

import javafx.application.Application;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.scene.paint.Paint;
import javafx.scene.text.Font;
import javafx.scene.text.FontWeight;
import javafx.scene.text.Text;
import javafx.stage.Stage;

public class TextPanel extends Application {

    GridPane grid = null;
    Text scenetitle = null;

    Label tDrawLabel = null;
    Label bsc345Label = null;
    HBox THBox = null;
    VBox mVBox = new VBox(2);
    Stage primaryStage = null;

    @Override
    public void start(Stage primaryStage) {

        this.primaryStage = primaryStage;

        grid = new GridPane();

        grid.setAlignment(Pos.CENTER);
        grid.setHgap(5);
        grid.setVgap(5);
        grid.setPadding(new Insets(20, 5, 20, 5));

        mVBox.setStyle("-fx-padding: 10;"
                + "-fx-border-style: solid inside;" + "-fx-border-width: 2;"
                + "-fx-border-insets: 5;" + "-fx-border-radius: 5;"
                + "-fx-border-color: blue;");
        scenetitle = new Text("Text Draw");
        scenetitle.setFont(Font.font("Tahoma", FontWeight.NORMAL, 20));
        grid.add(scenetitle, 1, 1, 1, 1);

        THBox = new HBox(4);


        tDrawLabel = new Label("TextDraw");
        tDrawLabel.setFont(new Font("Arial", 20));
        //textDrawLabel.setSpacing(10);
        tDrawLabel.setPadding(new Insets(0, 40, 10, 40));
        
        THBox.getChildren().add(tDrawLabel);

        mVBox.getChildren().add(THBox);
        bsc345Label = new Label("BSC 345");
        bsc345Label.setFont(new Font("Arial", 80));
        mVBox.getChildren().add(bsc345Label);

        primaryStage.setTitle("");
        Scene scene = new Scene(mVBox, 375, 225);
        primaryStage.setScene(scene);
        primaryStage.show();
    }

    /**
     * @param args
     * the command line arguments
     */
    public static void main(String[] args) {
        launch(args);
    }
}
0 0
Add a comment Improve this question Transcribed image text
Answer #1

javafx is a java package used for graphics and media related activities like adding rich text, buttons, events,effects and other related GUI components. As a whole Javafx is used to create rich text applications with a beautiful and interactive interfaces.

We have alot of options available with javafx like buttons,textareas,panels,grids etc which can be customized also, like in the program given here, mvBOX is customized by adding style elements.

Some of the components of javafx are as below: -

1. Java APIs - Javafx has a well defined API classes than can be used very easily just by importing them.

2. FXML - It is XML- based markup language used to design the application using XML declaratives.

3. Swing Interoperability :- Swing applications can be easily updated with javafx and web content.

4. Multitouch Support is there.

5. Canvas API - element to add drawing element in java panel. i.e. element to drawing directly within the area,

A javafx implementation typically has following parts which helps to implement a gui rich application.

1. A class extending Application( in case of application with no events) or ActionListner( in case of applicaiton with events/actions).

2. actionPerformed() method in case of applicaitons where events needs to be handled.

3.TextLabels, TextFields ,Buttons etc to show the elements in the screen.

4. for each of these components, classes are present and object can be instantiated and added to screens.

4. To add the objects to the screen, we can have Grids or Panels , which forms the layout of the application.

5. To handle the events of buttons, buttonObject.addActionListner(ActionListener al) method is used. We can pass the this reference in addActionListner if the class is extending to ActionListner.

6.to differentiate between different actions, we can use setActionCommand() method which takes a string as a parameter. Then in actionPerformed() method, we can use event.getActionCommand();

7. actionPerformed() method takes ActionEvent object as a parameter,which defines the current running event which needs to be handled. eg: -

@Override
public void actionPerformed(ActionEvent evt) {
     
   String actionCommand = evt.getActionCommand();
     
   if(actionCommand.equals("getBalance")) {
       balance.setText(getBal().toString());
   } else if(actionCommand.equals("getDescription")) {
       descriptionVal.setText(getDesc());
   } else if(actionCommand.equals("getDeposit")) {
       depositVal.setText(getDepos().toString());
   } else if(actionCommand.equals("setDescription")) {
       setDesc(description.getText());
   } else if(actionCommand.equals("setDeposit")) {
       setDepos(Double.parseDouble(deposit.getText()));
       setBal(bal + Double.parseDouble(deposit.getText()));
   }
  
}

In the application you stated in the question, there is no event handling needed. Just some text is shown with styling. Initially a grid is created and customized. Then HBox and VBox are used to create horizontal and verticle boxes in which text is added using Label which is styled furthur.

To run the applicaiton in main function launch method is used.

Output of the above application is shown below: -

TextDraw BSC 345

Add a comment
Know the answer?
Add Answer to:
Can someone please comment this on what the javafx do and how they are implemented? import...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • use this code of converting Km to miles , to create Temperature converter by using java...

    use this code of converting Km to miles , to create Temperature converter by using java FX import javafx.application.Application; import javafx.stage.Stage; import javafx.scene.Scene; import javafx.scene.layout.HBox; import javafx.scene.layout.VBox; import javafx.geometry.Pos; import javafx.geometry.Insets; import javafx.scene.control.Label; import javafx.scene.control.TextField; import javafx.scene.control.Button; import javafx.event.EventHandler; import javafx.event.ActionEvent; /** * Kilometer Converter application */ public class KiloConverter extends Application { // Fields private TextField kiloTextField; private Label resultLabel; public static void main(String[] args) { // Launch the application. launch(args); } @Override public void start(Stage primaryStage) { //...

  • Examine the following code and complete missing parts: import javafx.application.Application; import javafx.event.ActionEvent; import javafx.event.EventHandler; import javafx.geometry.Insets;...

    Examine the following code and complete missing parts: import javafx.application.Application; import javafx.event.ActionEvent; import javafx.event.EventHandler; import javafx.geometry.Insets; import javafx.geometry.Pos; import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.control.Label; import javafx.scene.control.TextField; import javafx.scene.layout.HBox; import javafx.scene.layout.VBox; import javafx.stage.Stage; public class NtoThePowerOfN extends Application{ @Override public void start(Stage primaryStage) throws Exception { TextField inputField; TextField outputField; VBox base = new VBox(10); base.setPadding(new Insets(10)); base.setAlignment(Pos.CENTER); // // A: input components - label and text field // // // B: button - to compute the value // // //...

  • Please Help, JavaFX assignment. This assignment will focus on the use anonymous inner class handlers to...

    Please Help, JavaFX assignment. This assignment will focus on the use anonymous inner class handlers to implement event handling. Assignment 12 Assignment 12 Submission Follow the directions below to submit Assignment 12: This assignment will be a modification of the Assignment 11 program. This program should use the controls and layouts from the previous assignment. No controls or layouts should be added or removed for this assignment. Add event handlers for the three buttons. The event handlers should be implemented...

  • / Finish the code to make it work import static javafx.application.Application.launch; import java.io.File; import javafx.application.Application; import...

    / Finish the code to make it work import static javafx.application.Application.launch; import java.io.File; import javafx.application.Application; import javafx.event.ActionEvent; import javafx.geometry.Insets; import javafx.geometry.Pos; import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.control.ChoiceBox; import javafx.scene.control.Label; import javafx.scene.layout.HBox; import javafx.scene.layout.VBox; import javafx.scene.media.AudioClip; import javafx.stage.Stage; public class JukeBox extends Application { private ChoiceBox<String> choice; private AudioClip[] tunes; private AudioClip current; private Button playButton, stopButton;    //----------------------- // presents an interface that allows the user to select and play // a tune from a drop down box //-----------------------   ...

  • Use Kilometer Converter application code to write Temperature Converter application to convert degrees Fahrenheit into degrees...

    Use Kilometer Converter application code to write Temperature Converter application to convert degrees Fahrenheit into degrees Celsius ((F - 32)*5/9). It needs to be JavaFX 1 import javafx.application. Application; 2 import javafx.stage. Stage; 3 import javafx.scene. Scene; 4 import javafx.scene.layout.HBox; 5 import javafx.scene.layout. VBox; 6 import javafx.geometry.Pos; 7 import javafx.geometry.Insets; 8 import javafx.scene.control.Label; 9 import javafx.scene.control. TextField; 10 import javafx.scene.control.Button; 11 import javafx.event. EventHandler; 12 import javafx.event. ActionEvent; 13 14 ** 15 * Kilometer Converter application 16 17 18 public...

  • Java Programming Assignment (JavaFX required). You will modify the SudokuCheckApplication program that is listed below. Start...

    Java Programming Assignment (JavaFX required). You will modify the SudokuCheckApplication program that is listed below. Start with the bolded comment section in the code below. Create a class that will take string input and process it as a multidimensional array You will modify the program to use a multi-dimensional array to check the input text. SudokuCheckApplication.java import javafx.application.*; import javafx.event.*; import javafx.geometry.*; import javafx.scene.*; import javafx.scene.control.*; import javafx.scene.layout.*; import javafx.stage.*; public class SudokuCheckApplication extends Application { public void start(Stage primaryStage)...

  • This is my code. I need the UML for this code My code: public class Main...

    This is my code. I need the UML for this code My code: public class Main extends FlightManager {    Stage window;    Scene scene;    Button button;    HBox layout = new HBox(20);    Label dateTxt, airlineTxt, originTxt, destTxt, clssTxt, scopeTxt, adultsTxt, childTxt;    @Override public void start(Stage stage) { // create the UI and show it here    window = stage; window.setTitle("Reservations 2020"); button = new Button("New Flight");    VBox group3 = new VBox(10); dateTxt = Text("", group3);...

  • (5 points) Analyze the following codes. b) import javafx.application.Application; import javafx.event.ActionEvent; import javafx.event.EventHandler; import javafx.scene.Scene; import...

    (5 points) Analyze the following codes. b) 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.HBox; import javafx.stage.Stage; public class Test extends Application { @Override // Override the start method in the Application class public void start(Stage primaryStage) { Button btOK = new Button("OK"); Button btCancel = new Button("Cancel"); EventHandler<ActionEvent> handler = new EventHandler<ActionEvent>() { public void handle(ActionEvent e) { System.out.println("The OK button is clicked"); } }; btOK.setOnAction(handler); btCancel.setOnAction(handler); HBox pane = new HBox(5); pane.getChildren().addAll(btOK, btCancel); Scene...

  • JavaFX! Just need to fill several lanes of code please!!! CSE205 OOP and Data Structure Quiz #15 Last Name (print) First Name (print) Write a JavaFX GUI application program that simulates a timer. T...

    JavaFX! Just need to fill several lanes of code please!!! CSE205 OOP and Data Structure Quiz #15 Last Name (print) First Name (print) Write a JavaFX GUI application program that simulates a timer. The timer should show "count: the beginning and increase the number by 1 in every one second, and so on. o" at .3 A Timer - × A Timer Count: 0 Count: 1 (B) After 1 second, the GUI Window (A) Initial GUI Window According to the...

  • please help me debug this Create a Future Value Calculator that displays error messages in labels.GUISpecificationsStart...

    please help me debug this Create a Future Value Calculator that displays error messages in labels.GUISpecificationsStart with the JavaFX version of the Future Value application presented in chapter 17. Create error message labels for each text field that accepts user input. Use the Validation class from chapter 17 to validate user input.Format the application so that the controls don’t change position when error messages are displayed. package murach.business; public class Calculation {        public static final int MONTHS_IN_YEAR =...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT