Great Deal! Get Instant $10 FREE in Account on First Order + 10% Cashback on Every Order Order Now

BCS 345 Lab 10 CRN 21177, XXXXXXXXXXJLi Spring 2020 ------------------------------------------------------------------------------------------------------------------------ Objectives: Get hands-on...

1 answer below »
BCS 345 Lab 10
CRN 21177, XXXXXXXXXXJLi Spring 2020
------------------------------------------------------------------------------------------------------------------------
Objectives: Get hands-on experience on creating GUI applications using JavaFX and Scene Builder.
Tasks:
In this lab, we will create a GUI application using JavaFX and Scene Builder. The interface has two tabs.
See PPT slides for methods related to RadioButton, CheckBox, Button, and ImageView GUI components.
1. Tab 1: Sandwich Cart
Create a graphical user interface to allow a user to enter first name and last name, select
sandwiches, and select a delivery option.
After the user clicks the “Submit Order” button. The order information, including user’s first name,
last name, order details, how the order will be delivered, and the amount due, is displayed.


2. Tab 2: ImageView
Create a graphical user interface to allow user to select and display an image with a RadioButton.
Answered Same Day May 04, 2021 BCS345

Solution

Yogesh answered on May 07 2021
139 Votes
JavaFXApp/src/sample/Controller.java
JavaFXApp/src/sample/Controller.java
package sample;
public class Controller {
}
JavaFXApp/src/sample/Main.java
JavaFXApp/src/sample/Main.java
package sample;
import javafx.application.Application;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Orientation;
import javafx.geometry.Rectangle2D;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.HBox;
import javafx.stage.Screen;
import javafx.stage.Stage;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
public class Main extends Application {
    public static void main(String[] args)
    {
        launch(args);
    }
    @Ove
ide
    public void start(Stage stage) throws FileNotFoundException {
        
 Set title for the Stage
        stage.setTitle(" ");
        Screen screen      = Screen.getPrimary();
        Rectangle2D bounds      = screen.getVisualBounds();
        
 Create TabPane
        TabPane tabBar     = new TabPane();
        
 Create Tabs
        Tab Scart     = new Tab("Sandwich Cart");
        Tab Iview     = new Tab("Image View");
        setScart(Scart);
        setIview(Iview);
        tabBar.getTabs().addAll(Scart, Iview);
        tabBar.setTabClosingPolicy(TabPane.TabClosingPolicy.UNAVAILABLE);
        BorderPane bp = new BorderPane();
        bp.setTop(new Label("\n "));
        bp.setCenter(tabBar);
        stage.setScene(new Scene(bp, 1000, 800));
        stage.show();
    }
    private void setIview(Tab tab) throws FileNotFoundException {
        GridPane root = new GridPane();
        
 Create Radio buttons for image select
        final ToggleGroup group1 = new ToggleGroup();
        RadioButton volcano = new RadioButton("Volcano\t\t\t\t\t");
        volcano.setToggleGroup(group1);
        volcano.setSelected(true);
        RadioButton accident = new RadioButton("Accident");
        accident.setToggleGroup(group1);
        
 Add Radio Buttons to the Hbox
        HBox hbox = new HBox();
        hbox.getChildren().addAll(new Label("\t\t\t\t\t"), volcano, accident);
        
 Get image file input and display as per the selected radio button
            
 Default image
        FileInputStream input = new FileInputStream("volcano.jpg");
        Image image = new Image(input);
        ImageView imgview = new ImageView(image);
        
 Check radio button and display image accordingly
        group1.selectedToggleProperty().addListener(new ChangeListene
Toggle>() {
            @Ove
ide
            public void changed(ObservableValue observable, Toggle oldValue, Toggle newValue) {
                if (group1.getSelectedToggle() == volcano){
                    try {
                        FileInputStream input = new FileInputStream("volcano.jpg");
                        Image image = new Image(input);
                        imgview.setImage(image);
                    } catch (FileNotFoundException e) {
                        e.printStackTrace();
                    }
                }
                else if (group1.getSelectedToggle() == accident){
                    try {
                        FileInputStream input = new FileInputStream("accident.jpg");
                        Image image = new Image(input);
                        imgview.setImage(image);
                    } catch (FileNotFoundException e) {
                        e.printStackTrace();
                    }
                }
            }
        });
        
 Set image Size
        imgview.setFitHeight(620);
        imgview.setFitWidth(800);
        
 Add contents to grid
        root.add(new Label("\t\t\n"), 0, 0);
        root.add(imgview, 1, 1);
        root.add( new Label(""), 1, 2);
        root.add(hbox, 1, 3);
        
 Add main grid to the ta
        tab.setContent(root);
    }
    private void setScart(Tab tab) {
        
 Split tab into two sections
        SplitPane section = new SplitPane();
        
 Grid for order plac...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here