Question

In: Computer Science

Topic is relates to Java programming! Code using java GUI 2. Create the following controls: a)...

Topic is relates to Java programming! Code using java GUI

2. Create the following controls:
a) a TextField
b) a Button
c) a Text
d) a Label
3. create the following container and put them the above controls:
a) a VBox controller
b) a BorderPane controller
c) a GridPane

Solutions

Expert Solution

The program is written in Java 8 using Eclipse IDE and Scene Builder for UI design

Main

package test;

import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.stage.Stage;
import javafx.scene.Parent;
import javafx.scene.Scene;

public class Main extends Application {
   @Override
   public void start(Stage primaryStage) {
       try {
           // loading the FXML File
           Parent root = FXMLLoader.load(getClass().getResource("FXML.fxml"));
           Scene scene = new Scene(root);
           primaryStage.setScene(scene);
           primaryStage.setResizable(false);// seting resizable false
           primaryStage.setTitle("");// set title
           primaryStage.show();
       } catch (Exception e) {
           e.printStackTrace();
       }
   }

   public static void main(String[] args) {
       launch(args);
   }
}

Controller

package test;

import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.VBox;
import javafx.scene.text.Text;

public class Controller {

@FXML
private BorderPane borderPane;//borderpane control

@FXML
private GridPane gridPane;//gridpane control

@FXML
private VBox vbox;//vbox control

@FXML
private Text text1;//text control

@FXML
private TextField textfield;//textfield control

@FXML
private Label label;//label control

@FXML
private Button button;//button control

@FXML//perform button operation
void buttonOperation(ActionEvent event) {
   //set the textfiled text to label on button click
   label.setText(textfield.getText());
}

}

FXML

<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.layout.BorderPane?>
<?import javafx.scene.layout.ColumnConstraints?>
<?import javafx.scene.layout.GridPane?>
<?import javafx.scene.layout.RowConstraints?>
<?import javafx.scene.layout.VBox?>
<?import javafx.scene.text.Text?>

<BorderPane fx:id="borderPane" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8.0.171" xmlns:fx="http://javafx.com/fxml/1" fx:controller="test.Controller">
<center>
<GridPane fx:id="gridPane" BorderPane.alignment="CENTER">
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
</columnConstraints>
<rowConstraints>
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
</rowConstraints>
<children>
<VBox fx:id="vbox" prefHeight="69.0" prefWidth="225.0">
<children>
<Text fx:id="text1" strokeType="OUTSIDE" strokeWidth="0.0" text="Text" />
<TextField fx:id="textfield" promptText="TextField" />
<Label fx:id="label" prefHeight="24.0" prefWidth="300.0" text="Label" />
<Button fx:id="button" mnemonicParsing="false" onAction="#buttonOperation" prefHeight="33.0" prefWidth="70.0" text="Click Me" />
</children>
</VBox>
</children>
</GridPane>
</center>
</BorderPane>

Output


Related Solutions

PYTHON PROGRAMMING Using tktinker, create a gui that surrounds the code below that has buttons and...
PYTHON PROGRAMMING Using tktinker, create a gui that surrounds the code below that has buttons and labels and an overall theme. # Meet the chatbot Eve print('Hi there! Welcome to the ChatBot station. I am going to ask you a series of questions and all you have to do is answer!') print(' ') print('Lets get started') #begin questions firstName = input('What is your first name?: ') lastName = input('What is your last name? ') print("Hi there, ", firstName + lastName,...
Create a java Swing GUI application that presents the user with a “fortune”. Create a java...
Create a java Swing GUI application that presents the user with a “fortune”. Create a java Swing GUI application in a new Netbeans project called FortuneTeller. Your project will have a FortuneTellerFrame.java class (which inherits from JFrame) and a java main class: FortuneTellerViewer.java. Your application should have and use the following components: Top panel: A JLabel with text “Fortune Teller” (or something similar!) and an ImageIcon. Find an appropriate non-commercial Fortune Teller image for your ImageIcon. (The JLabel has a...
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.  
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT