In: Computer Science
I need a Java application with a GUI that includes the following requirements:
I was thinking of something with an ordering system for a restaurant, or something with a school, students, instructors, ID’s, grades, and GPA’s.
The deliverables needed will be the code and GUI, along with a UML that shows the classes.
Example of get; set; method.
{
abstract class Photo
{
public double Height { get; set; }
public double Width { get; set; }
public double Price { get; set; }
public abstract void DisplayPhotoInfo();
}
}
There are a total of 6 Files:-
Model Classes:-
1.Food.java
2.Drinks.java
Abstract Class
3.Price.java
Controller File
4.FXMLDocumentController.java
FXML frontend FXML File
5.FXMLDocument.fxml
.Main File
6.MyRestaurantFX.java
Below are the codes of the above files:-
1.Food.java
package myrestaurantfx;
public class Food extends Price{
private String foodName;
public String getFoodName() {
return foodName;
}
public void setFoodName(String foodName) {
this.foodName = foodName;
}
public float getPrice() {
return price;
}
public void setPrice(float price) {
this.price = price;
}
}
2.Drinks.java
package myrestaurantfx;
public class Drinks extends Price{
private String drinksName;
public String getDrinksName() {
return drinksName;
}
public void setDrinksName(String drinksName) {
this.drinksName = drinksName;
}
public float getPrice() {
return price;
}
public void setPrice(float price) {
this.price = price;
}
}
3.Price.java
package myrestaurantfx;
public class Drinks extends Price{
private String drinksName;
public String getDrinksName() {
return drinksName;
}
public void setDrinksName(String drinksName) {
this.drinksName = drinksName;
}
public float getPrice() {
return price;
}
public void setPrice(float price) {
this.price = price;
}
}
4.FXMLDocumentController.java
package myrestaurantfx;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.ResourceBundle;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TextArea;
import javafx.scene.control.TextField;
public class FXMLDocumentController implements Initializable
{
// Linking textfields, buttons and textarea with frontend
@FXML
private Label label;
@FXML
TextField foodTF,drinksTF;
@FXML
Button orderFoodBtn,orderDrinksBtn;
@FXML
TextArea orderTextArea;
@Override
public void initialize(URL url, ResourceBundle rb) {
}
@FXML
public void orderFood(ActionEvent ev)
{
Food food=new Food();
String foodName=foodTF.getText();
food.setFoodName(foodName);
ordersPlaced(food);
System.out.print("orderDrink");
}
@FXML
public void orderDrinks(ActionEvent ev)
{
Drinks drinks=new Drinks();
String drinksName=drinksTF.getText();
drinks.setDrinksName(drinksName);
ordersPlaced(drinks);
System.out.print("orderDrink");
}
public void ordersPlaced(Object item)
{
String items="";
if(item instanceof Food)
{
items=((Food) item).getFoodName();
}
else if(item instanceof Drinks)
{
items=((Drinks) item).getDrinksName();
}
orderTextArea.setText(orderTextArea.getText()+"\n"+"Your order of
"+ items +" is placed"+ "\n");
}
}
5.FXMLDocument.fxml
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.TextArea?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.layout.AnchorPane?>
<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity"
minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0"
prefWidth="600.0" xmlns="http://javafx.com/javafx/8.0.111"
xmlns:fx="http://javafx.com/fxml/1"
fx:controller="myrestaurantfx.FXMLDocumentController">
<children>
<Label layoutX="218.0" layoutY="36.0" prefHeight="17.0"
prefWidth="109.0" style="-fx-background-color: #9ef59d;" text="MY
RESTAURANT" textAlignment="RIGHT" />
<Label layoutX="115.0" layoutY="86.0"
style="-fx-background-color: #f5bc42;" text="FOOD" />
<Label layoutX="355.0" layoutY="86.0"
style="-fx-background-color: #f5bc42;" text="DRINKS" />
<TextField fx:id="foodTF" layoutX="74.0" layoutY="121.0"
/>
<TextField fx:id="drinksTF" layoutX="316.0" layoutY="121.0"
/>
<Button fx:id="orderFoodBtn" layoutX="98.0" layoutY="167.0"
mnemonicParsing="false" onAction="#orderFood" prefHeight="25.0"
prefWidth="102.0" style="-fx-background-color: #9dd4f5;"
text="ORDER FOOD" />
<Button fx:id="orderDrinksBtn" layoutX="346.0" layoutY="167.0"
mnemonicParsing="false" onAction="#orderDrinks" prefHeight="25.0"
prefWidth="109.0" style="-fx-background-color: #9dd4f5;"
text="ORDER DRINKS" />
<TextArea fx:id="orderTextArea" layoutX="88.0" layoutY="251.0"
prefHeight="102.0" prefWidth="368.0" />
<Label layoutX="206.0" layoutY="219.0" prefHeight="17.0"
prefWidth="109.0" style="-fx-background-color: #d89df5;" text="YOUR
ORDERS" />
<Label layoutX="75.0" layoutY="103.0" prefHeight="17.0"
prefWidth="135.0" style="-fx-background-color: #42f5ce;"
text="Bread | Omlette | Chicken" />
<Label layoutX="323.0" layoutY="103.0" prefHeight="17.0"
prefWidth="135.0" style="-fx-background-color: #42f5ce;"
text="Coke| Whiskey| Wine" />
</children>
</AnchorPane>
MyRestaurantFX .java
package myrestaurantfx;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;
public class MyRestaurantFX extends Application {
@Override
public void start(Stage stage) throws Exception {
Parent root =
FXMLLoader.load(getClass().getResource("FXMLDocument.fxml"));
Scene scene = new Scene(root);
stage.setTitle("MyRestaurant JavaFx Project");
stage.setScene(scene);
stage.show();
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
launch(args);
}
}
Package Structure:
GUI screen
UML Diagram:
The Project is written in Netbeans IDE using Gluon
SceneBuilder.