0% found this document useful (0 votes)
2 views

Ass1 Java

Uploaded by

rohanshedge2006
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Ass1 Java

Uploaded by

rohanshedge2006
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 30

ASSIGNMENT NO 1

Project title:- Restaurant Management System (source code)


Customer :-
 Customer.java :-
package customerPackage;

import gustorestaurant.MyConnection;
import gustorestaurant.User;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import menuItems.Inventory;
import menuItems.MainMenu;
import menuItems.MenuItem;
import starting.LoginForm;
import starting.SignUpForm;

public class Customer extends User {


private String address;
private int id;
private ArrayList<Order> orders = new ArrayList<>();
private Order tempOrder = new Order();

public int getId() {


return id;
}

public String getMobilePhone() {


return mobilePhone;
}
public Customer(int id, String name, String username, String mobilePhone,
String password, String address, ArrayList<Order> o) {
super(name, username, mobilePhone, password);
this.id = id;
this.address = address;
this.orders = o;
}

public Customer(int id, String name, String username, String mobilePhone,


String password, String address) {
super(name, username, mobilePhone, password);
this.id = id;
this.address = address;
}

public void placeOrders(Order order) {


tempOrder = order;
orders.add(order);
}

public void complain(String message) {


tempOrder.setComplainMessage(message);
}

public void rating(String foodItem, double rate) {


tempOrder.ratings.put(foodItem, rate);
}

public void returnOrder(Order order) {


orders.remove(order);
}

public void cancelOrder() {


long currentTime = System.currentTimeMillis();
Date cancellationTime = new Date(tempOrder.getCanelTimeInMillis());
if (tempOrder.getCanelTimeInMillis() >= currentTime && !
BillForm.delivered) {
returnOrder(tempOrder);
BillForm.returned = true;
JOptionPane.showMessageDialog(null, "The order has been cancelled\
nThank you for your visit", "Cancel", JOptionPane.INFORMATION_MESSAGE);
} else {
JOptionPane.showMessageDialog(null, "Unfortunately you can't
cancel the order now", "Error", JOptionPane.ERROR_MESSAGE);
}
}

public String getAddress() {


return address;
}

public Order getTempOrder() {


return tempOrder;
}

public ArrayList<Order> getOrders() {


return orders;
}

public String getName() {


return name;
}

public void setTempOrder(Order tempOrder) {


this.tempOrder = tempOrder;
}

public void setAddress(String address) {


this.address = address;
}

public static int getNoCustomers() {


int count = 0;
try {
PreparedStatement preparedStmt =
MyConnection.getConnection().prepareStatement("SELECT count(*) FROM
menu_item.customer");
ResultSet rs = preparedStmt.executeQuery();
if (rs.next()) {
count = rs.getInt("count(*)");
}
} catch (SQLException ex) {
Logger.getLogger(Customer.class.getName()).log(Level.SEVERE, null,
ex);
}
return count;
}

public Customer() {}

@Override
public boolean register() {
boolean registered = false;
PreparedStatement ps = null;
ResultSet rs;
String query = "SELECT * FROM customer WHERE customer_username
= ?";
try {
ps = MyConnection.getConnection().prepareStatement(query);
ps.setString(1, this.userName);
rs = ps.executeQuery();
if (rs.next()) {
JOptionPane.showMessageDialog(null, "This Username Already
Exists");
SignUpForm.setTextField();
return registered;
} else {
query = "INSERT INTO `customer`(`customer_username`,
`customer_mobile`, `customer_password`, `customer_name`,
`customer_address`, `customer_id`, `customer_listOfOrders`) VALUES
(?,?,?,?,?,?,?)";
ps = MyConnection.getConnection().prepareStatement(query);
String encrypted = User.encryptThisString(this.password);
ps.setString(1, this.userName);
ps.setString(2, this.mobilePhone);
ps.setString(3, encrypted);
ps.setString(4, this.name);
ps.setString(5, this.address);
ps.setInt(6, this.id);
ps.setString(7, null);
this.password = encrypted;
if (ps.executeUpdate() > 0) {
CustomerWelcomeForm cf = new CustomerWelcomeForm(this,
null);
cf.setVisible(true);
registered = true;
}
}
} catch (SQLException ex) {
Logger.getLogger(Customer.class.getName()).log(Level.SEVERE, null,
ex);
}
return registered;
}

@Override
public boolean login(String cuserName, String cPassword) {
boolean loggedIn = false;
PreparedStatement ps;
ResultSet rs;
String query = "SELECT * FROM customer WHERE
customer_username=? AND customer_password=?";
try {
ps = MyConnection.getConnection().prepareStatement(query);
String encrypted = User.encryptThisString(cPassword);
ps.setString(1, cuserName);
ps.setString(2, encrypted);
rs = ps.executeQuery();
if (rs.next()) {
String cphone = rs.getString("customer_mobile");
String cname = rs.getString("customer_name");
String caddress = rs.getString("customer_address");
int cid = rs.getInt("customer_id");
String ordersString = rs.getString("customer_listOfOrders");
if (ordersString != null) {
this.orders = convertStringtoOrders(ordersString);
}
Customer c = new Customer(cid, cname, cuserName, cphone,
cPassword, caddress, this.orders);
CustomerWelcomeForm cf = new CustomerWelcomeForm(c,
ordersString);
cf.setVisible(true);
loggedIn = true;
} else {
LoginForm.setTextFields();
JOptionPane.showMessageDialog(null, "Username or password
incorrect.", "Login Failed", JOptionPane.ERROR_MESSAGE);
}
} catch (SQLException ex) {
Logger.getLogger(Customer.class.getName()).log(Level.SEVERE, null,
ex);
}
return loggedIn;
}

private ArrayList<Order> convertStringtoOrders(String s) {


ArrayList<Order> OrderItems = new ArrayList<>();
Order o;
String[] order = s.split("/");
for (String a : order) {
int x = Integer.valueOf(a);
PreparedStatement ps = null;
ResultSet rs;
String query = "SELECT * FROM order_info WHERE order_id = ?";
try {
ps = MyConnection.getConnection().prepareStatement(query);
ps.setInt(1, x);
rs = ps.executeQuery();
if (rs.next()) {
String cid = String.valueOf(this.id);
String cname = this.name;
String oid = String.valueOf(x);
String caddress = this.address;
String cmobile = this.mobilePhone;
String oname = rs.getString("order_cutomerName");
String oboy = rs.getString("order_deliveryBoy");
String ocomplain = rs.getString("order_complainMessage");
boolean status = rs.getBoolean("order_receivedStatus");
long startinMillis = rs.getLong("order_StartMillis");
long deliveryinMillis = rs.getLong("order_DeliveryMillis");
HashMap<String, Integer> orderList = new HashMap<>();
String menuString = rs.getString("order_menuItemList");
String[] allOrders = menuString.split("&");
for (String z : allOrders) {
String[] specific = z.split("#");
int q = Integer.valueOf(specific[1]);
orderList.put(specific[0], q);
}
o = new Order(oid, cid, cname, caddress, cmobile);
o.setComplainMessage(ocomplain);
o.setStartTimeInMillis(startinMillis);
o.setDeliveryTimeInMillis(deliveryinMillis);
o.setStatus(status);
o.setAssociatedDeliveryBoyId(oboy);
o.setOrderList(orderList);
OrderItems.add(o);
} else {
JOptionPane.showMessageDialog(null, "Order not found");
}
} catch (SQLException ex) {
Logger.getLogger(Customer.class.getName()).log(Level.SEVERE,
null, ex);
}
}
return OrderItems;
}

public static void viewBestSellers() {


ArrayList<MenuItem> orderedList;
for (String category : MainMenu.categoryList.keySet()) {
orderedList = MainMenu.categoryList.get(category);
Collections.sort(orderedList, Collections.reverseOrder());
String bestItem = orderedList.get(0).getItemName();
String rate = String.valueOf(orderedList.get(0).getItemRate());
String numberOfRates =
String.valueOf(Inventory.inventoryList.get(orderedList.get(0).getItemName())
.getNumberOfRates());
BestSellerForm.jTextArea1.append("From " + category + ": \n");
BestSellerForm.jTextArea1.append(bestItem + ", ");
BestSellerForm.jTextArea1.append("rated " + rate + "/5 by " +
numberOfRates + " users.");
BestSellerForm.jTextArea1.append("\n\n");
}
}
}

 Billform.java :-

package customerPackage;

/*
* To change this license header, choose License Headers in Project
Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
import customerPackage.OrderForm.*;
import customerPackage.OrderForm;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.*;
import javafx.util.Pair;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import menuItems.Inventory;

/**
*
* @author Dell
*/
public class BillForm extends javax.swing.JFrame
{
//Order order = new Order();

Bill bill;
String ordersS;
int totalCash;
int rate;
static boolean returned = false;
Voucher exceed1000 = new Voucher("Exceed1000", 20);
boolean rated=false;
boolean pressedStatusBtn=false;
static boolean delivered=false;
/**
* Creates new form BillForm
*/
public BillForm()
{
initComponents();
pnl_rate.setVisible(false);
pnl_bill.setVisible(true);
lbl_complain.setVisible(false);
txt_complainMessege.setVisible(false);
btn_closeRating.setVisible(false);
}

}//GEN-LAST:event_btn_finishRateActionPerformed

private void
btn_nextRateActionPerformed(java.awt.event.ActionEvent evt) {//GEN-
FIRST:event_btn_nextRateActionPerformed
// TODO add your handling code here:

if ("".equals(txt_getRate.getText()))
{
if (OrderForm.currentOrder.ratings.size() > 1)
{
lbl_complain.setVisible(true);
txt_complainMessege.setVisible(true);
btn_closeRating.setVisible(true);
}
else
{
JOptionPane.showMessageDialog(this, "Please rate at least
one element", "Error", JOptionPane.ERROR_MESSAGE);
}
}
else
{

OrderForm.currentOrder.ratings.put(String.valueOf(cbx_ChooseItemToR
ate.getSelectedItem()), Double.valueOf(txt_getRate.getText()));
txt_getRate.setText("");
}
}//GEN-LAST:event_btn_nextRateActionPerformed

private void
btn_cancelOrderActionPerformed(java.awt.event.ActionEvent evt)
{//GEN-FIRST:event_btn_cancelOrderActionPerformed
// cancel order
OrderForm.customer.cancelOrder();
}//GEN-LAST:event_btn_cancelOrderActionPerformed
private void
btn_orderStatusActionPerformed(java.awt.event.ActionEvent evt)
{//GEN-FIRST:event_btn_orderStatusActionPerformed
// TODO add your handling code here:
if (OrderForm.currentOrder.checkStatus(OrderForm.currentOrder))
{
System.out.println(OrderForm.deliveryBoy.getOrdersList().size()
+" we are in the orderStatusBtn");

OrderForm.deliveryBoy.getOrdersList().remove(OrderForm.currentOrder
);
System.out.println(OrderForm.deliveryBoy.getOrdersList().size()
+" we are in the orderStatusBtn");

OrderForm.deliveryBoy.setAvailable(true);

//OrderForm.currentOrder.updateDeliveryBoys(OrderForm.deliveryBoy);
delivered=true;
JOptionPane.showMessageDialog(this, "Your order is done",
"Served", JOptionPane.OK_OPTION);
}

else
{
JOptionPane.showMessageDialog(this, "Your order is being
cooked", "Loading...", JOptionPane.OK_OPTION);
}

OrderForm.currentOrder.updateDeliveryBoys(OrderForm.deliveryBoy);
pressedStatusBtn=true;
}//GEN-LAST:event_btn_orderStatusActionPerformed

/**
* @param args the command line arguments
*/
public static void main(String args[])
{
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel
setting code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with
the default look and feel.
* For details see
http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.htm
l
*/
try
{
for (javax.swing.UIManager.LookAndFeelInfo info :
javax.swing.UIManager.getInstalledLookAndFeels())
{
if ("Nimbus".equals(info.getName()))
{

javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex)
{

java.util.logging.Logger.getLogger(BillForm.class.getName()).log(java.u
til.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex)
{

java.util.logging.Logger.getLogger(BillForm.class.getName()).log(java.u
til.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex)
{

java.util.logging.Logger.getLogger(BillForm.class.getName()).log(java.u
til.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex)
{

java.util.logging.Logger.getLogger(BillForm.class.getName()).log(java.u
til.logging.Level.SEVERE, null, ex);
}
//</editor-fold>

/* Create and display the form */


java.awt.EventQueue.invokeLater(new Runnable()
{
public void run()
{
new BillForm().setVisible(true);
}
});
}

// Variables declaration - do not modify//GEN-BEGIN:variables


private javax.swing.JButton btn_backFromBill;
private javax.swing.JButton btn_cancelOrder;
private javax.swing.JButton btn_closeRating;
private javax.swing.JButton btn_finishRate;
private javax.swing.JButton btn_nextRate;
private javax.swing.JButton btn_orderStatus;
private javax.swing.JButton btn_rate;
private javax.swing.JComboBox<String> cbx_ChooseItemToRate;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JSeparator jSeparator1;
private javax.swing.JLabel lbl_OrderType;
private javax.swing.JLabel lbl_complain;
private javax.swing.JLabel lbl_rate;
private javax.swing.JPanel pnl_bill;
private javax.swing.JPanel pnl_rate;
private javax.swing.JTextArea txtArea_bill;
private javax.swing.JTextField txt_complainMessege;
private javax.swing.JTextField txt_getRate;
// End of variables declaration//GEN-END:variables
}

Manager :-

 Manager.java :-

/*
* To change this license header, choose License Headers in Project
Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package managerPackage;

import customerPackage.DeliveryBoy;
import gustorestaurant.MyConnection;
import gustorestaurant.User;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import menuItems.Inventory;
import menuItems.InventoryForm;
import menuItems.InventoryItem;
import menuItems.MainMenu;
import menuItems.MenuItem;
import starting.HomepageForm;
import starting.LoginForm;
import starting.SignUpForm;

/**
*
* @author PC
*/
public class Manager extends User
{

public Manager(String name, String username, String mobilePhone, String


password)
{
super(name, username, mobilePhone, password);
}

public Manager()
{

public String getName()


{
return name;
}

void addDeliveryBoy(DeliveryBoy deliveryBoy)


{
try
{

String Query = "INSERT INTO menu_item.delivery_boys


(id_delivery_boys ,name_delivery_boys ,start_time_delivery_boys,finish_time_
delivery_boys ,status_delivery_boys ,orderList_delivery_boys)"
+ " VALUES (?,?,?,?,?,?,?)";

PreparedStatement preparedStmt =
MyConnection.getConnection().prepareStatement(Query);

preparedStmt.setString(1, deliveryBoy.getId());
preparedStmt.setString(2, deliveryBoy.getName());
preparedStmt.setString(3, String.valueOf(deliveryBoy.getStart()));
preparedStmt.setString(4, String.valueOf(deliveryBoy.getEnd()));
preparedStmt.setInt(5, 1);
preparedStmt.setString(6, null);
preparedStmt.setString(7, null);
preparedStmt.execute();

} catch (SQLException ex)


{
Logger.getLogger(Manager.class.getName()).log(Level.SEVERE, null,
ex);
}
}

public void addInventoryItem(String itemName, int itemPrice, String


CategoryName, int avaliable_quantity)
{
Boolean itemFound = false;
String query; // Database Query
int itemID = 0; //variable to set id for item
MenuItem menuitem = new MenuItem();
InventoryItem inventory = new InventoryItem();

//To Check if menu item already exists


for (int i = 0; i < MainMenu.categoryList.get(CategoryName).size(); ++i)
{

if
(MainMenu.categoryList.get(CategoryName).get(i).getItemName().equals(ite
mName))
{
JOptionPane.showMessageDialog(null, "This Item already exists");
itemFound = true;
break;
}
}
if (!itemFound)
{
try
{
//Add new added item into database in menu_item table
query = "INSERT INTO menu_item ( idmenu_item,
namemenu_item,rankmenu_item , pricemenu_item , category )" + "
VALUES(?,?,?,?,?)";
PreparedStatement preparedStmt =
MyConnection.getConnection().prepareStatement(query);
//Set random itemID
itemID = Inventory.inventoryList.size() + 1;
preparedStmt.setInt(1, itemID);
preparedStmt.setString(2, itemName);
preparedStmt.setInt(3, 0);
preparedStmt.setInt(4, itemPrice);
preparedStmt.setString(5, CategoryName);
if (preparedStmt.executeUpdate() > 0)
{
JOptionPane.showMessageDialog(null, "New item is added ");
//To add new addded item to my main menu map
menuitem.setItemId(itemID);
menuitem.setItemName(itemName);
menuitem.setItemPrice(itemPrice);
menuitem.setItemRate(0);
MainMenu.categoryList.get(CategoryName).add(menuitem);
//To display new added item info on table
InventoryForm.model.addRow(new Object[]
{
itemID, itemName, 0, 0, avaliable_quantity
});
}

} catch (SQLException ex)


{

Logger.getLogger(Manager.class.getName()).log(Level.SEVERE,
null, ex);
}
try
{
//Add new inventory info in database in inventory table
query = "INSERT INTO inventory ( item_id , units_sold ,
avaliable_quantity , number_rate)" + " VALUES(?,?,?,?)";
PreparedStatement preparedStmt =
MyConnection.getConnection().prepareStatement(query);
preparedStmt.setInt(1, itemID);
preparedStmt.setInt(2, 0);
preparedStmt.setInt(3, avaliable_quantity);
preparedStmt.setInt(4, 0);
preparedStmt.execute();
//To add new added item in inventory List
inventory.setMenuItem(menuitem);
inventory.setAvaliableMenuItem(avaliable_quantity);
inventory.setSoldMenuItem(0);
Inventory.inventoryList.put(menuitem.getItemName(), inventory);

} catch (SQLException ex)


{
Logger.getLogger(Manager.class.getName()).log(Level.SEVERE,
null, ex);
}
}

public void viewInventoryItem(String categoryName)


{
String itemName;
try
{
//Looping over categoryList(main menu map) to display List of
menuItem and inventoryItem of choosen category on table
for (int i = 0; i < MainMenu.categoryList.get(categoryName).size(); +
+i)
{
//getting item name to get inventory info from inventoryList map
with itemNam(key of map)
itemName =
MainMenu.categoryList.get(categoryName).get(i).getItemName();

//Getting Inventory Info from Inventory List And Display it on table


//Getting from categoryList(main menu map)
menuItemID,menuItemName,menuItemRate
//Getting from inventoryList(inventory map)
inventoryItemUnits_sold, inventoryItemAvaliable_Quantity
//Displaying info on table
InventoryForm.model.addRow(new Object[]
{
MainMenu.categoryList.get(categoryName).get(i).getItemId(),
MainMenu.categoryList.get(categoryName).get(i).getItemName(),
MainMenu.categoryList.get(categoryName).get(i).getItemRate(),
Inventory.inventoryList.get(itemName).getSoldMenuItem(),
Inventory.inventoryList.get(MainMenu.categoryList.get(categoryName).get(i).
getItemName()).getAvaliableMenuItem()
});

}
} catch (Exception e)
{
JOptionPane.showMessageDialog(null, "Please Choose one
Category");
}
}

public void deleteInventoryItem(int deleteId, String categoryName)


{
try
{
//Delete Menu Item from menu item table in database
String query = "delete from menu_item where idmenu_item = ? ";
PreparedStatement preparedStmt =
MyConnection.getConnection().prepareStatement(query);
preparedStmt.setInt(1, deleteId);

if (preparedStmt.executeUpdate() > 0)
{
JOptionPane.showMessageDialog(null, "Item Deleted");

//Search in categoryList(main menu map) for deleteItemID to


delete it from map
//After getting name of deleteItem from categoryList delete it from
inventoryList(inventory map)
for (int i = 0; i < MainMenu.categoryList.get(categoryName).size();
++i)
{
if (MainMenu.categoryList.get(categoryName).get(i).getItemId()
== deleteId)
{
//getting name of item from categoryList
String iname =
MainMenu.categoryList.get(categoryName).get(i).getItemName();

//Remove menu item from main menu map (main menu map)
MenuItem removedMenuItem = new MenuItem();
removedMenuItem =
MainMenu.categoryList.get(categoryName).remove(i);

//Remove Inventory item from inventory list map


InventoryItem removedInventoryItem = new InventoryItem();
if (Inventory.inventoryList.containsKey(iname))
{
removedInventoryItem =
Inventory.inventoryList.remove(iname);
}

//Delete item row from table


InventoryForm.model.removeRow(i);
break;

}
}
} catch (SQLException ex)
{
Logger.getLogger(Manager.class.getName()).log(Level.SEVERE, null,
ex);
}
try
{
//Delete Inventory Item from inventory table in database
String query = "delete from inventory where item_id= ? ";
PreparedStatement preparedStmt =
MyConnection.getConnection().prepareStatement(query);
preparedStmt.setInt(1, deleteId);
preparedStmt.execute();
} catch (SQLException ex)
{
Logger.getLogger(Manager.class.getName()).log(Level.SEVERE, null,
ex);
}
}

public void addAnnouncement(Announcement a)


{
HomepageForm.offers.add(a);
String items = convertItemstoString(a.menuItems);
PreparedStatement ps;
String query = "INSERT INTO `announcements`(`managerName`,
`message`, `menuItems`, `price`) VALUES (?,?,?,?)";
try
{
ps = MyConnection.getConnection().prepareStatement(query);
ps.setString(1, this.name);
ps.setString(2, a.message);
ps.setString(3, items);
ps.setInt(4, a.price);
boolean execute = ps.execute();
} catch (SQLException ex)
{
Logger.getLogger(Manager.class.getName()).log(Level.SEVERE, null,
ex);
}
}

//manage delievery boys


@Override
public boolean register()
{
boolean registered = false;
PreparedStatement ps;
ResultSet rs;
String query = "SELECT * FROM manager WHERE manager_username
=?";
try
{
ps = MyConnection.getConnection().prepareStatement(query);
ps.setString(1, this.userName);
rs = ps.executeQuery();
if (rs.next())
{
JOptionPane.showMessageDialog(null, "This Username Already
Exists");
SignUpForm.setTextField();
}
else
{
query = "INSERT INTO `manager`(`manager_username`,
`manager_mobile`, `manager_password`, `manager_name`) VALUES
(?,?,?,?)";
ps = MyConnection.getConnection().prepareStatement(query);

String encrypted = User.encryptThisString(this.password);


this.password = encrypted;
ps.setString(1, this.userName);
ps.setString(2, this.mobilePhone);
ps.setString(3, this.password);
ps.setString(4, this.name);

if (ps.executeUpdate() > 0)
{
//JOptionPane.showMessageDialog(null, "New User Add");
Manager m = new Manager(this.name, this.userName,
this.mobilePhone, this.password);
ManagerWelcomeForm mf = new ManagerWelcomeForm(m);
mf.setVisible(true);
}
}
} catch (SQLException ex)
{
Logger.getLogger(Manager.class.getName()).log(Level.SEVERE, null,
ex);
}
return registered;
}

/**
*
* @param muserName
* @param mPassword
* @return
*/
@Override
public boolean login(String muserName, String mPassword)
{
boolean loggedIn = false;
PreparedStatement ps;
ResultSet rs;
String query = "SELECT * FROM manager WHERE manager_username=?
AND manager_password=?";
try
{
String encrypted = User.encryptThisString(mPassword);
ps = MyConnection.getConnection().prepareStatement(query);
ps.setString(1, muserName);
ps.setString(2, encrypted);
rs = ps.executeQuery();
if (rs.next())
{
String mphone = rs.getString("manager_mobile");
String mname = rs.getString("manager_name");
Manager m = new Manager(mname, muserName, mphone,
mPassword);
ManagerWelcomeForm mf = new ManagerWelcomeForm(m);
mf.setVisible(true);
loggedIn = true;
}
else
{
LoginForm.setTextFields();
JOptionPane.showMessageDialog(null, "Username or password
incorrect.", "Login Failed", JOptionPane.ERROR_MESSAGE);
}

} catch (SQLException ex)


{
System.out.println("fail");
Logger.getLogger(Manager.class.getName()).log(Level.SEVERE, null,
ex);
}
return loggedIn;
}
}

Menu:-

 menu.java :-

package menuItems;

import java.awt.Color;
import java.util.HashMap;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import menuItems.MainMenu;
import static starting.HomepageForm.offers;

public class Menu extends javax.swing.JFrame


{

String itemInfo;
String itemName;
String itemPrice;
String itemRate;
String Dots = "";

static JPanel pnl_tmp; // Panel as a Tab


static JLabel lbl_tmp; // label for background
static JScrollPane JscrlP_tmp;// ScrollPane for TextArea
static JTextArea txtA_tmp; // TextArea to print text in
static JLabel lbl_pic1; // lable for menu item image
static JLabel lbl_pic2; // ,, ,, ,, ,, ,,
static JLabel lbl_pic3; // ,, ,, ,, ,, ,,
static JLabel lbl_pic4; // ,, ,, ,, ,, ,,

void createPanel()
{
//Define new tab to hold this tittle & add it to JTabbedPane
pnl_tmp = new JPanel();
pnl_tmp.setLayout(null);

// setting label for background


lbl_tmp = new JLabel();
lbl_tmp.setBackground(new java.awt.Color(255, 255, 255));
lbl_tmp.setForeground(new java.awt.Color(255, 255, 255));
lbl_tmp.setBounds(0, 0, 1216, 788); //
************************************************* to be changed
lbl_tmp.setIcon(new
ImageIcon(getClass().getResource("/restaurant/Pic/MainMenubackground2.pn
g")));
pnl_tmp.add(lbl_tmp);

// Define a JScrollPane to hold JTextarea


JscrlP_tmp = new JScrollPane();
JscrlP_tmp.setOpaque(false);
JscrlP_tmp.getViewport().setOpaque(false);
JscrlP_tmp.setBounds(0, 0, 1210, 780);//
************************************************* to be changed

// Define the JTextarea to hold my text (list of menu items in this


category )
txtA_tmp = new JTextArea(10, 2);
txtA_tmp.setEditable(false);
txtA_tmp.setBackground(new Color(0, 0, 0, 0));
txtA_tmp.setForeground(new java.awt.Color(255, 255, 255));
txtA_tmp.setFont(new java.awt.Font("Tempus Sans ITC", 1, 24)); //
************************************************* to be changed // Rockwell
Condensed
txtA_tmp.setOpaque(false);
//to make JscrlP_tmp transparent
JscrlP_tmp.setViewportView(txtA_tmp);
pnl_tmp.add(JscrlP_tmp);

// Setting Menu Items Images as icons of labels (only three Items)


lbl_pic1 = new JLabel();
pnl_tmp.add(lbl_pic1);
lbl_pic1.setBounds(jLabel1.getBounds());

lbl_pic2 = new JLabel();


pnl_tmp.add(lbl_pic2);
lbl_pic2.setBounds(jLabel2.getBounds());

lbl_pic3 = new JLabel();


pnl_tmp.add(lbl_pic3);
lbl_pic3.setBounds(jLabel3.getBounds());

lbl_pic4 = new JLabel();


pnl_tmp.add(lbl_pic4);
lbl_pic4.setBounds(jLabel7.getBounds());

//set priorty of components in the panel


pnl_tmp.setComponentZOrder(lbl_pic1, 0);
pnl_tmp.setComponentZOrder(lbl_pic2, 1);
pnl_tmp.setComponentZOrder(lbl_pic3, 2);
}

public Menu()
{

initComponents();
showMainMenu();
this.setLocationRelativeTo(null); //center form in screen
}

@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-
BEGIN:initComponents
private void initComponents()
{

pnl_LogoBar = new javax.swing.JPanel();


lbl_RsturantName = new javax.swing.JLabel();
tpnl_ViewMainMenu = new javax.swing.JTabbedPane();
jPanel2 = new javax.swing.JPanel();
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
jLabel3 = new javax.swing.JLabel();
jLabel7 = new javax.swing.JLabel();

setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE
);
setTitle("Main Menu");
setMaximumSize(new java.awt.Dimension(1216, 788));
setPreferredSize(new java.awt.Dimension(1217, 788));
setSize(new java.awt.Dimension(1217, 788));

pnl_LogoBar.setBackground(new java.awt.Color(255, 213, 0));

lbl_RsturantName.setFont(new java.awt.Font("Rockwell Condensed", 0,


48)); // NOI18N
lbl_RsturantName.setForeground(new java.awt.Color(102, 0, 102));
lbl_RsturantName.setText("GUSTO");

javax.swing.GroupLayout pnl_LogoBarLayout = new


javax.swing.GroupLayout(pnl_LogoBar);
pnl_LogoBar.setLayout(pnl_LogoBarLayout);
pnl_LogoBarLayout.setHorizontalGroup(

pnl_LogoBarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.
LEADING)
.addGroup(pnl_LogoBarLayout.createSequentialGroup()
.addGap(530, 530, 530)
.addComponent(lbl_RsturantName)
.addContainerGap(588, Short.MAX_VALUE))
);
pnl_LogoBarLayout.setVerticalGroup(

pnl_LogoBarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.
LEADING)
.addGroup(pnl_LogoBarLayout.createSequentialGroup()
.addContainerGap()
.addComponent(lbl_RsturantName)
.addContainerGap(16, Short.MAX_VALUE))
);

tpnl_ViewMainMenu.setBackground(new java.awt.Color(255, 213, 0));


tpnl_ViewMainMenu.setForeground(new java.awt.Color(102, 0, 102));

tpnl_ViewMainMenu.setTabLayoutPolicy(javax.swing.JTabbedPane.SCROLL_TA
B_LAYOUT);
tpnl_ViewMainMenu.setToolTipText("");
tpnl_ViewMainMenu.setAutoscrolls(true);
tpnl_ViewMainMenu.setCursor(new
java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
tpnl_ViewMainMenu.setFont(new java.awt.Font("Rockwell", 3, 24)); //
NOI18N
tpnl_ViewMainMenu.setName(""); // NOI18N
tpnl_ViewMainMenu.setPreferredSize(new java.awt.Dimension(1216,
70));

jLabel1.setBackground(new java.awt.Color(0, 204, 153));


jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
jLabel1.setPreferredSize(new java.awt.Dimension(230, 230));

jLabel2.setText("jLabel2");
jLabel2.setPreferredSize(new java.awt.Dimension(230, 230));

jLabel3.setFont(new java.awt.Font("Vladimir Script", 0, 11)); // NOI18N


jLabel3.setText("jLabel3");
jLabel3.setPreferredSize(new java.awt.Dimension(230, 230));

jLabel7.setText("jLabel7");
jLabel7.setPreferredSize(new java.awt.Dimension(230, 230));

javax.swing.GroupLayout jPanel2Layout = new


javax.swing.GroupLayout(jPanel2);
jPanel2.setLayout(jPanel2Layout);
jPanel2Layout.setHorizontalGroup(

jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADI
NG)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING,
jPanel2Layout.createSequentialGroup()
.addContainerGap(75, Short.MAX_VALUE)
.addComponent(jLabel7,
javax.swing.GroupLayout.PREFERRED_SIZE, 230,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(61, 61, 61)
.addComponent(jLabel1,
javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(63, 63, 63)
.addComponent(jLabel3,
javax.swing.GroupLayout.PREFERRED_SIZE, 230,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(59, 59, 59)
.addComponent(jLabel2,
javax.swing.GroupLayout.PREFERRED_SIZE, 251,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap())
);
jPanel2Layout.setVerticalGroup(

jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAIL
ING)
.addGroup(javax.swing.GroupLayout.Alignment.LEADING,
jPanel2Layout.createSequentialGroup()
.addGap(329, 329, 329)
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLa
yout.Alignment.LEADING)
.addComponent(jLabel7,
javax.swing.GroupLayout.PREFERRED_SIZE, 230,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.Group
Layout.Alignment.TRAILING)
.addComponent(jLabel1,
javax.swing.GroupLayout.PREFERRED_SIZE, 244,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.Gro
upLayout.Alignment.BASELINE)
.addComponent(jLabel2,
javax.swing.GroupLayout.PREFERRED_SIZE, 230,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel3,
javax.swing.GroupLayout.PREFERRED_SIZE, 230,
javax.swing.GroupLayout.PREFERRED_SIZE))))
.addContainerGap(63, Short.MAX_VALUE))
);

tpnl_ViewMainMenu.addTab("tab1", jPanel2);

javax.swing.GroupLayout layout = new


javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(

layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(pnl_LogoBar,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(tpnl_ViewMainMenu,
javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE)
);
layout.setVerticalGroup(

layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(pnl_LogoBar,
javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.R
ELATED)
.addComponent(tpnl_ViewMainMenu,
javax.swing.GroupLayout.PREFERRED_SIZE, 679,
javax.swing.GroupLayout.PREFERRED_SIZE))
);

tpnl_ViewMainMenu.getAccessibleContext().setAccessibleName("");
pack();
}// </editor-fold>//GEN-END:initComponents

public static void main(String args[])


{
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting
code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the
default look and feel.
* For details see
http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try
{
for (javax.swing.UIManager.LookAndFeelInfo info :
javax.swing.UIManager.getInstalledLookAndFeels())
{
if ("Nimbus".equals(info.getName()))
{
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex)
{

java.util.logging.Logger.getLogger(Menu.class.getName()).log(java.util.loggin
g.Level.SEVERE, null, ex);
} catch (InstantiationException ex)
{

java.util.logging.Logger.getLogger(Menu.class.getName()).log(java.util.loggin
g.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex)
{

java.util.logging.Logger.getLogger(Menu.class.getName()).log(java.util.loggin
g.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex)
{
java.util.logging.Logger.getLogger(Menu.class.getName()).log(java.util.loggin
g.Level.SEVERE, null, ex);
}
//</editor-fold>

/* Create and display the form */


java.awt.EventQueue.invokeLater(new Runnable()
{
public void run()
{
new Menu().setVisible(true);
}

});
}
// Variables declaration - do not modify//GEN-BEGIN:variables
public static javax.swing.JLabel jLabel1;
public static javax.swing.JLabel jLabel2;
public static javax.swing.JLabel jLabel3;
public static javax.swing.JLabel jLabel7;
private javax.swing.JPanel jPanel2;
private javax.swing.JLabel lbl_RsturantName;
private javax.swing.JPanel pnl_LogoBar;
public static javax.swing.JTabbedPane tpnl_ViewMainMenu;
// End of variables declaration//GEN-END:variables
}

You might also like