Skip Top Navigation Bar

Rewards App JavaFX Starter Code

Duke with a scroll.READ THIS IMPORTANT MESSAGE

Complete ALL steps in this section before looking at errors. You will have errors after Step 1. Don't panic!! Complete ALL steps before you attempt to fix bugs.

Step 1: Set up your project files

Set up a project in the IDE of your choice (we recommend intelliJ) and add the following classes to your project:

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

<?import javafx.geometry.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.image.*?>
<?import javafx.scene.layout.*?>

<VBox alignment="TOP_CENTER" prefHeight="764.0" prefWidth="670.0" spacing="20.0" xmlns="http://javafx.com/javafx/17.0.2-ea" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.example.rewardsappjavafx.HelloController">
    <padding>
        <Insets bottom="20.0" left="20.0" right="20.0" top="20.0" />
    </padding>
   <ImageView fitHeight="303.0" fitWidth="357.0" pickOnBounds="true" preserveRatio="true">
      <image>
         <Image url="@sandwichlogo.jpg" />
      </image>
   </ImageView>
   <AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="100.0" prefWidth="630.0">
      <children>
          <Button fx:id="RegistrationButton" layoutX="120.0" layoutY="60.0" onAction="#onRegisterButtonClick" text="Register" textAlignment="CENTER" />
         <Button fx:id="rewardsButton" layoutX="425.0" layoutY="60.0" mnemonicParsing="false" onAction="#onRewardsButtonClick" text="Rewards" textAlignment="CENTER" />
         <Label layoutX="132.0" layoutY="33.0" prefHeight="17.0" prefWidth="367.0" text="Click Register to sign-up and Rewards to see your available rewards" />
      </children>
   </AnchorPane>
</VBox>

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

<?import javafx.geometry.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.image.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.text.*?>

<VBox alignment="TOP_CENTER" prefHeight="764.0" prefWidth="670.0" spacing="20.0" xmlns="http://javafx.com/javafx/17.0.2-ea" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.example.rewardsappweb.RegistrationController">
    <padding>
        <Insets bottom="20.0" left="20.0" right="20.0" top="20.0" />
    </padding>
    <ImageView fitHeight="321.0" fitWidth="458.0" pickOnBounds="true" preserveRatio="true">
        <image>
            <Image url="@sandwichlogohorizonatal.jpg" />
        </image>
    </ImageView>
    <AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="100.0" prefWidth="630.0">
        <children>
            <Button fx:id="RegistrationButton" layoutX="120.0" layoutY="60.0" onAction="#onRegisterButtonClick" text="Register" textAlignment="CENTER" />
            <Button fx:id="rewardsButton" layoutX="425.0" layoutY="60.0" mnemonicParsing="false" onAction="#onRewardsButtonClick" text="Rewards" textAlignment="CENTER" />
            <Label layoutX="120.0" layoutY="29.0" prefHeight="17.0" prefWidth="362.0" text="Click Register to sign-up and Rewards to see your available rewards" />
        </children>
    </AnchorPane>
    <AnchorPane fx:id="registrationInfoInput" prefHeight="250.0" prefWidth="200.0">
        <children>
            <TextField fx:id="firstNameText" layoutX="41.0" layoutY="22.0" prefHeight="25.0" prefWidth="228.0" promptText="First Name" />
            <TextField fx:id="lastNameText" layoutX="315.0" layoutY="22.0" prefHeight="25.0" prefWidth="271.0" promptText="Last Name" />
            <TextField fx:id="streetAddress1Text" layoutX="41.0" layoutY="63.0" prefHeight="25.0" prefWidth="541.0" promptText="Street Address 1" />
            <TextField fx:id="streetAddress2Text" layoutX="41.0" layoutY="100.0" prefHeight="25.0" prefWidth="541.0" promptText="Street Address 2" />
            <TextField fx:id="cityText" layoutX="41.0" layoutY="142.0" prefHeight="25.0" prefWidth="307.0" promptText="City" />
            <TextField fx:id="stateText" layoutX="362.0" layoutY="142.0" prefHeight="25.0" prefWidth="51.0" promptText="State" />
            <TextField fx:id="zipText" layoutX="437.0" layoutY="142.0" promptText="Zip" />
            <TextField fx:id="emailAddressText" layoutX="41.0" layoutY="191.0" prefHeight="25.0" prefWidth="541.0" promptText="Email" />
        </children>
    </AnchorPane>
    <AnchorPane fx:id="customIdPane" prefHeight="200.0" prefWidth="200.0">
        <children>
            <Label fx:id="accountSetUpLabel" layoutX="276.0" layoutY="76.0" prefHeight="25.0" prefWidth="338.0" text="CONGRATULATION! You have set up your account!" visible="false">
                <font>
                    <Font size="14.0" />
                </font>
            </Label>
            <Label fx:id="customerIdLabel" layoutX="39.0" layoutY="89.0" prefHeight="27.0" prefWidth="78.0" text="Customer Id: " />
            <Label fx:id="customerIdText" layoutX="360.0" layoutY="115.0" prefHeight="27.0" prefWidth="78.0" />
            <Button fx:id="submitRegistrationButton" layoutX="534.0" layoutY="22.0" mnemonicParsing="false" onAction="#onSubmitRegistrationButtonClick" text="Submit" />
        </children>
    </AnchorPane>
</VBox>

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

<?import javafx.geometry.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.image.*?>
<?import javafx.scene.layout.*?>

<VBox alignment="CENTER" prefHeight="764.0" prefWidth="670.0" spacing="20.0" xmlns="http://javafx.com/javafx/17.0.2-ea" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.example.rewardsappweb.RewardsController">
    <padding>
        <Insets bottom="20.0" left="20.0" right="20.0" top="20.0" />
    </padding>
    <ImageView fitHeight="321.0" fitWidth="458.0" pickOnBounds="true" preserveRatio="true">
        <image>
            <Image url="@sandwichlogohorizonatal.jpg" />
        </image>
    </ImageView>
    <AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="100.0" prefWidth="600.0">
        <children>
            <Button fx:id="RegistrationButton" layoutX="120.0" layoutY="60.0" onAction="#onRegisterButtonClick" text="Register" textAlignment="CENTER" />
            <Button fx:id="rewardsButton" layoutX="425.0" layoutY="60.0" mnemonicParsing="false" onAction="#onRewardsButtonClick" text="Rewards" textAlignment="CENTER" />
            <Label layoutX="118.0" layoutY="14.0" maxHeight="-Infinity" prefHeight="17.0" prefWidth="365.0" text="Click Register to sign-up and Rewards to see your available rewards" />
        </children>
    </AnchorPane>
    <AnchorPane fx:id="registrationInfoInput" prefHeight="200.0" prefWidth="200.0">
        <children>
            <TextField fx:id="customerIdText" layoutX="34.0" layoutY="36.0" prefHeight="25.0" prefWidth="280.0" promptText="Enter Your Customer Id" />
            <Button layoutX="444.0" layoutY="61.0" mnemonicParsing="false" onAction="#showRewards" text="viewRewardsButton" />
        </children></AnchorPane>
    <AnchorPane prefHeight="200.0" prefWidth="200.0">
        <children>
            <Label fx:id="displayRewardsLabel" layoutX="44.0" layoutY="25.0" prefHeight="140.0" prefWidth="555.0" />
        </children>
    </AnchorPane>
</VBox>

Step 2: FXML Resources

Add the following to your resources with the code provided:

Each of these files have a line that includes something like com.example.rewardsappjavafx.HelloController. You will need to change this to point to the folder where your controller is stored. Your change will be something like com.example.WhateverYouNamedYourProject.HelloController.

Step 3: Text Files Needed

In your resources, add the following:

Step 4: Images Needed

In your resources, add the following:

Return to Missions