Hotelcalifornia Java

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 38

/**

* Title: HotelCalifornia.java
* Abstract: My cancelation "works" from what I can tell, in the
background, however, it does not display the updated profile in
the ViewFrame class
* and I do not have any password security checking.
* Resource used:
* stackoverflow.com
* coderanch.com
* http://docs.oracle.com/javase/tutorial/
* Author: [Tyler Nicholson]
* ID: [3131]
* Date: [5-8-13]
*/
import
import
import
import
import
import
import
import
import
import
import
import
import
import
import
import
import
import
import
import
import
import
import
import
import
import

javax.swing.JFrame;
javax.swing.JPanel;
java.awt.FlowLayout;
java.awt.GridBagConstraints;
java.awt.GridBagLayout;
java.awt.GridLayout;
java.awt.Insets;
java.awt.event.ActionEvent;
java.awt.event.ActionListener;
javax.swing.BorderFactory;
javax.swing.ButtonGroup;
javax.swing.JButton;
javax.swing.JComboBox;
javax.swing.JLabel;
javax.swing.JOptionPane;
javax.swing.JRadioButton;
javax.swing.JTextField;
javax.swing.SwingUtilities;
javax.swing.border.BevelBorder;
javax.swing.border.Border;
javax.swing.JTextArea;
java.util.ArrayList;
java.util.HashMap;
java.util.Map;
java.util.Map.Entry;
java.util.Set;

public class HotelCalifornia


{
public static void main(String[] args) {
JFrame frame = new MainMenuFrame();
frame.setVisible(true);
}
}
class MainMenuFrame extends JFrame

{
public MainMenuFrame()
{
setTitle("Hotel Reservation System");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel panel = new MainMenuPanel();
this.add(panel);
this.setSize(400, 200);
}
}
class MainMenuPanel extends JPanel
{
private JButton signIn,
makeAccount,
exitButton;
// Listener for the make account button
private class MainAccountListener implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
Object source = e.getSource();
if (source == exitButton)
{
System.exit(0);
}
else if(source == makeAccount)
{
JFrame frame1 = new MakeAccountFrame();
frame1.setVisible(true);
}
else if(source == signIn)
{
JFrame frame2 = new SignInAccountFrame();
frame2.setVisible(true);
}
}
}
public MainMenuPanel()
{
this.setLayout(new GridBagLayout());
// Create buttons
signIn = new JButton("Sign In");
makeAccount = new JButton("Register Account");
exitButton = new JButton("Exit");

// Action listener for the Make Account button


makeAccount.addActionListener(new MainAccountListener());
//Action listener for the Exit button
exitButton.addActionListener(new MainAccountListener());
//Action listener for the Sign In button
signIn.addActionListener(new MainAccountListener());
//Layout for the JFrame of the Main Window
GridBagConstraints gc = new GridBagConstraints();
gc.gridx = 0;
gc.gridy = 0;
gc.anchor = GridBagConstraints.CENTER;
this.add(signIn, gc);
gc.gridy = 1;
this.add(makeAccount, gc);
gc.gridy = 2;
this.add(exitButton, gc);
}
public static HashMap<String, ArrayList<Object>> map = new
HashMap<String, ArrayList<Object>>();
public static ArrayList<Object> information = new
ArrayList<Object>();
public static ArrayList<Object> blocked = new
ArrayList<Object>();
private static String heldname;
private static String heldpass;
public static boolean adminCheck()//checking if there is
admin account
{
if(map.containsKey("admin"))
{
return true;
}
else
{
return false;
}
}
public static void callStorage(String name,
ArrayList<Object> items)//adding new user + password to hashmap
{
information=items;
map.put(name, items);
System.out.println(map); //HashMap Container check
}
public static boolean checker(String name)//for sign in

username check
{
if(map.containsKey(name))
{
setHold(name);
return true;
}
else
{
return false;
}
}
public static void setHold(String name)
{
heldname = name;
}
public static String getHold()
{
return heldname;
}
private static int cost;
private static String room;
private static int nights;
public static void setRoom(String theRoom)
{
room=theRoom;
}
public static String getRoom()
{
return room;
}
public static void setCost(int theCost)
{
cost=theCost;
}
public static int getCost()
{
return cost;
}
public static void setTime(int time)
{
nights=time;
}
public static int getTime()
{
return nights;
}
public static void alteration(String room, int nights,int
cost)//for creating a reservation
{
information = map.get(getHold());

information.add(room);
information.add(nights);
information.add(cost);
System.out.println(map); //HashMap Container
check
}
public static boolean passCheck(String pass)
{
if(map.get(getHold()).contains(pass))
{
information = map.get(getHold());
System.out.println(information.get(0));
return true;
}
else
{
return false;
}
}
public static void passChanger(String pass) //method for
changing password
{
information = map.get(getHold());
information.set(0, pass);
System.out.println(information.get(0));//replace check
System.out.println(map); //HashMap Container check
}
public static String retrieval()//for viewing account
information
{
String output;
System.out.println(map.get(getHold()));
if(information.size()>1)
{
output="Room: "+information.get(1)+"\nNumber of
Nights: "+information.get(2)+"\nCost: $"+information.get(3);
}
else
{
output="Room: No room reserved"+"\nNumber of
Nights: 0"+"\nCost: $0";
}
return output;
}
public static void cancelation()
{
if(information.size()>1)

{
information = map.get(getHold());
information.remove(1);
information.remove(1);
information.remove(1);
}
System.out.println(map); //HashMap Container check
}
public static boolean existing()//method for checking if
user already has a reservation
{
if(information.size()<1)
{
return false;
}
else if(information.size()>1 &&
!information.get(1).equals("No room reserved"))
{
return true;
}
else
{
return false;
}
}
public static boolean replace()//reservation after
cancelation
{
information = map.get(getHold());
if(information.size()>1 &&
information.get(1).equals("No room reserved"))
{
return true;
}
else
{
return false;
}
}
public static String grab()//method for administration view
of entire "database"
{
ArrayList<String> statement= new ArrayList<String>();
String output="";
for(Entry<String, ArrayList<Object>> entry :
map.entrySet())
{
String key = entry.getKey();
Object value = entry.getValue();

if(key.equals("admin"))
{
}
else
{
statement.add("User: "+key+"\nInformation:
"+value+"\n");
output = statement.toString();
}
}
return output;
}
public static void blocker()//method for removing all
elements behind blocked key and blocking key
{
map.remove(getHold());
blocked.add(getHold());
System.out.println(blocked);
}
public static boolean blockCheck(String name)
{
if(blocked.contains(name))
{
return true;
}
else
{
return false;
}
}
}
//GUI for Making an Account (below)
class MakeAccountFrame extends JFrame
{
public MakeAccountFrame()
{
setTitle("Make Account");
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
JPanel panel = new MakeAccountPanel();
this.add(panel);
this.setSize(400, 200);
}
}
class MakeAccountPanel extends JPanel

{
private JButton submitButton,
cancelButton;
private JTextField textFieldUser,
textFieldPass;
private JLabel userLabel,
passLabel;
ArrayList<Object> customerInfo = new ArrayList<Object>();
ArrayList<Object> temp = new ArrayList<Object>();
// Listener for the Submit button
private class SubmitListener implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
if(!textFieldUser.getText().equals("") &&
!textFieldPass.getText().equals(""))
{
if(MainMenuPanel.blockCheck(textFieldUser.getText())==true)
{
JOptionPane.showMessageDialog(null, "This
username has been blocked.");
}
else
if(MainMenuPanel.checker(textFieldUser.getText())==true)
{
//Just display a message.
JOptionPane.showMessageDialog(null,
"Username already exists.");
}
else
{
if(MainMenuPanel.adminCheck()==false)
{
temp.add("admin");
MainMenuPanel.callStorage("admin",
temp);
}
if(textFieldUser.getText().equals("admin"))
{
JOptionPane.showMessageDialog(null,
"Username already exists.");
}
else
{
//info stored in arraylist object form
customerInfo.add(textFieldPass.getText());

//HashMap storage, username is key and


arraylist is object behind it
MainMenuPanel.callStorage(textFieldUser.getText(), customerInfo);
//Just display a message.
JOptionPane.showMessageDialog(null,
"Account has been created.");
//once user hits ok they will be brought
back to the main menu
backToMain();
}
}
}
else
{
JOptionPane.showMessageDialog(null, "All
fields must be completed.");
}
}
}
// Listener for the Cancel button
private class CancelListener implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
backToMain();
}
}
public void backToMain()
{
SwingUtilities.getWindowAncestor(this).dispose();
}
// Creates the new MakeAccountPanel
public MakeAccountPanel()
{
setLayout(new GridBagLayout());
JPanel textField = new JPanel();
textField.setLayout(new GridLayout(4,4));
JPanel buttonPanel = new JPanel( );
buttonPanel.setLayout(new FlowLayout( ));
//Sets the labels, textFields, and buttons
submitButton = new JButton("Submit");
buttonPanel.add(submitButton);

cancelButton = new JButton("Cancel");


buttonPanel.add(cancelButton);
add(buttonPanel, getConstraints(0,3,3,1,
GridBagConstraints.WEST));
submitButton.addActionListener(new SubmitListener());
cancelButton.addActionListener(new CancelListener());
userLabel = new JLabel("Username");
add(userLabel, getConstraints(0,0,3,1,
GridBagConstraints.WEST));
passLabel = new JLabel("Password");
add(passLabel, getConstraints(0,1,3,1,
GridBagConstraints.WEST));
textFieldUser = new JTextField(8);
add(textFieldUser, getConstraints(1,0,3,1,
GridBagConstraints.EAST));
textFieldPass = new JTextField(8);
add(textFieldPass, getConstraints(1,1,3,1,
GridBagConstraints.EAST));
textFieldUser.addActionListener(new SubmitListener());
textFieldPass.addActionListener(new SubmitListener());
}
private GridBagConstraints getConstraints(int gridx, int
gridy,int gridwidth, int gridheight, int anchor)
{
GridBagConstraints c = new GridBagConstraints();
c.insets = new Insets(2, 5, 2, 5);
c.ipadx = 0;
c.ipady = 0;
c.gridx = gridx;
c.gridy = gridy;
c.gridwidth = gridwidth;
c.gridheight = gridheight;
c.anchor = anchor;
return c;
}
}
//GUI for Signing in (below)
class SignInAccountFrame extends JFrame
{
public SignInAccountFrame()
{

setTitle("Log In Account");
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
JPanel panel = new SignInAccountPanel();
this.add(panel);
this.setSize(400, 200);
}
}
class SignInAccountPanel extends JPanel
{
private JButton enterButton,
cancelButton;
private JTextField textFieldUserLog,
textFieldPassLog;
private JLabel userLabel,
passLabel;
// Listener for the Submit button
private class EnterListener implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
Object source = e.getSource();
if(source==enterButton)
{
if(textFieldUserLog.getText().equals("admin") &&
textFieldPassLog.getText().equals("admin"))
{
JFrame set = new OptionsFrame();
set.setVisible(true);
backToMain();
}
else
{
if(!textFieldUserLog.getText().equals("")
&& !textFieldPassLog.getText().equals(""))
{
if(MainMenuPanel.blockCheck(textFieldUserLog.getText())==true)
{
JOptionPane.showMessageDialog(null,
"This account has been blocked.");
}
else
if(MainMenuPanel.checker(textFieldUserLog.getText())==false)//use
rname check
{
//Just display a message.

JOptionPane.showMessageDialog(null, "Invalid Username or


Password.");
}
else
if(MainMenuPanel.passCheck(textFieldPassLog.getText())==false)//p
assword check
{
//Just display a message.
JOptionPane.showMessageDialog(null,
"Invalid Username or Password.");
}
else
{
if(textFieldUserLog.getText().equals("admin") &&
textFieldPassLog.getText().equals("admin"))
{
JFrame set = new
SystemFrame();
set.setVisible(true);
backToMain();
}
else
{
MainMenuPanel.setHold(textFieldUserLog.getText());
//continues on to Choice
window
JFrame caller = new
ChoiceFrame();
caller.setVisible(true);
//closes SignInAccountFrame
class's window
backToMain();
}
//Just display a message.
JOptionPane.showMessageDialog(null,
"Sign In completed.");
}
}
else
{
JOptionPane.showMessageDialog(null, "All fields must be
completed.");
}
}
}

}
}
// Listener for the Cancel button
private class CancelListener implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
backToMain();
}
}
// Goes back to the main menu frame
public void backToMain()
{
(SwingUtilities.getWindowAncestor(this)).dispose();
}
// Creates the new MakeAccountPanel
public SignInAccountPanel()
{
this.setLayout(new GridBagLayout());
JPanel textField = new JPanel();
textField.setLayout(new GridLayout(4,4));
JPanel buttonPanel = new JPanel( );
buttonPanel.setLayout(new FlowLayout( ));
//Sets the buttons
enterButton = new JButton("Enter");
buttonPanel.add(enterButton);
cancelButton = new JButton("Cancel");
buttonPanel.add(cancelButton);
add(buttonPanel, getConstraints(0,3,3,1,
GridBagConstraints.WEST));
enterButton.addActionListener(new EnterListener());
cancelButton.addActionListener(new CancelListener());
userLabel = new JLabel("Username");
add(userLabel, getConstraints(0,0,3,1,
GridBagConstraints.WEST));
passLabel = new JLabel("Password");
add(passLabel, getConstraints(0,1,3,1,
GridBagConstraints.WEST));
textFieldUserLog = new JTextField(8);
add(textFieldUserLog, getConstraints(1,0,3,1,

GridBagConstraints.EAST));
textFieldPassLog = new JTextField(8);
add(textFieldPassLog, getConstraints(1,1,3,1,
GridBagConstraints.EAST));
textFieldUserLog.addActionListener(new EnterListener());
textFieldPassLog.addActionListener(new EnterListener());
}
private GridBagConstraints getConstraints(int gridx, int
gridy,int gridwidth, int gridheight, int anchor)
{
GridBagConstraints c = new GridBagConstraints();
c.insets = new Insets(2, 5, 2, 5);
c.ipadx = 0;
c.ipady = 0;
c.gridx = gridx;
c.gridy = gridy;
c.gridwidth = gridwidth;
c.gridheight = gridheight;
c.anchor = anchor;
return c;
}
}
//GUI for Reserving or Canceling or Changing Password or Logging
out (below)
class ChoiceFrame extends JFrame
{
public ChoiceFrame()
{
setTitle("Option Page");
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
JPanel panel = new ChoicePanel();
this.add(panel);
this.setSize(400, 200);
}
}
class ChoicePanel extends JPanel
{
private JButton reservingButton,
cancelingButton,
viewingButton,
passchangeButton,
logoutButton;
private JTextField textFieldUser,
textFieldPass;
private JLabel userLabel,
passLabel;

// Listener for class Choice's buttons


private class ChoiceActionListener implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
Object source = e.getSource();
if(source==reservingButton)
{
if(MainMenuPanel.existing()==true)
{
JOptionPane.showMessageDialog(null,
"Account already has reservation.");
}
else
{
// goes to reservation window
JFrame caller = new ReserveFrame();
caller.setVisible(true);
backToMain();
}
}
else if(source==cancelingButton)
{
if(MainMenuPanel.existing()==false)
{
JOptionPane.showMessageDialog(null,
"Account has no reservation.");
}
else
{
// goes to canceling window
JFrame caller = new CancelFrame();
caller.setVisible(true);
backToMain();
}
}
else if(source==viewingButton)
{
// goes to viewing window
JFrame caller = new ViewingFrame();
caller.setVisible(true);
backToMain();
MainMenuPanel.retrieval();
}
else if(source==passchangeButton)
{

// goes to password changing window


JFrame caller = new PasswordFrame();
caller.setVisible(true);
backToMain();
}
else if(source==logoutButton)
{
backToMain();
}
else
{
JOptionPane.showMessageDialog(null, "Invalid
seleciton.");
}
}
}
public void backToMain()
{
(SwingUtilities.getWindowAncestor(this)).dispose();
}
public ChoicePanel()
{
this.setLayout(new GridBagLayout());
JPanel buttonPanel = new JPanel( );
buttonPanel.setLayout(new FlowLayout( ));
//Sets the buttons
reservingButton = new JButton("Make Reservation");
buttonPanel.add(reservingButton);
cancelingButton = new JButton("Cancel Reservation");
buttonPanel.add(cancelingButton);
viewingButton = new JButton("View Profile");
buttonPanel.add(viewingButton);
passchangeButton = new JButton("Change Password");
buttonPanel.add(passchangeButton);
logoutButton = new JButton("Log Out");
buttonPanel.add(logoutButton);
reservingButton.addActionListener(new
ChoiceActionListener());
cancelingButton.addActionListener(new
ChoiceActionListener());
viewingButton.addActionListener(new
ChoiceActionListener());
passchangeButton.addActionListener(new
ChoiceActionListener());

logoutButton.addActionListener(new
ChoiceActionListener());
//Layout for the JFrame of the Main Window
GridBagConstraints gc = new GridBagConstraints();
gc.gridx = 0;
gc.gridy = 0;
gc.anchor = GridBagConstraints.CENTER;
this.add(reservingButton, gc);
gc.gridy = 1;
this.add(cancelingButton, gc);
gc.gridy = 2;
this.add(viewingButton, gc);
gc.gridy = 3;
this.add(passchangeButton, gc);
gc.gridy = 4;
this.add(logoutButton, gc);
}
}
//GUI for reservations (below)
class ReserveFrame extends JFrame
{
public ReserveFrame()
{
setTitle("Reservations Page");
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
JPanel panel = new ReservePanel();
this.add(panel);
this.setSize(400, 200);
}
}
class ReservePanel extends JPanel
{
private JButton continueButton,
backButton;
private JRadioButton singleRadioButton,
doubleRadioButton,
suiteRadioButton;
private JComboBox nightsBox;
private int price;
private class ContinueActionListener implements
ActionListener
{
public void actionPerformed(ActionEvent e)
{
Object source = e.getSource();

if(source==continueButton &&
(singleRadioButton.isSelected() || doubleRadioButton.isSelected()
|| suiteRadioButton.isSelected()))
{
if(singleRadioButton.isSelected())
{
price=100;
if(MainMenuPanel.replace()==true)
{
MainMenuPanel.cancelation();
MainMenuPanel.setRoom("single");
MainMenuPanel.setTime(1);
MainMenuPanel.setCost(100);
}
else
{
MainMenuPanel.setRoom("single");
MainMenuPanel.setTime(1);
MainMenuPanel.setCost(100);
}
}
else if(doubleRadioButton.isSelected())
{
price=200;
if(MainMenuPanel.replace()==true)
{
MainMenuPanel.cancelation();
MainMenuPanel.setRoom("double");
MainMenuPanel.setTime(1);
MainMenuPanel.setCost(200);
}
else
{
MainMenuPanel.setRoom("double");
MainMenuPanel.setTime(1);
MainMenuPanel.setCost(200);
}
}
else if(suiteRadioButton.isSelected())
{
price=300;
if(MainMenuPanel.replace()==true)
{
MainMenuPanel.cancelation();
MainMenuPanel.setRoom("suite");

MainMenuPanel.setTime(1);
MainMenuPanel.setCost(300);
}
else
{
MainMenuPanel.setRoom("suite");
MainMenuPanel.setTime(1);
MainMenuPanel.setCost(300);
}
}
JFrame confirm = new ConfirmationFrame();
confirm.setVisible(true);
backToMain();
}
else if(source==backButton)
{
JFrame choices = new ChoiceFrame();
choices.setVisible(true);
backToMain();
}
else
{
JOptionPane.showMessageDialog(null, "Invalid
Reservation Request.");
}
}
}
public void backToMain()
{
(SwingUtilities.getWindowAncestor(this)).dispose();
}
public ReservePanel()
{
this.setLayout(new GridBagLayout());
JPanel textField = new JPanel();
textField.setLayout(new GridLayout(4,4));
JPanel buttonPanel = new JPanel( );
buttonPanel.setLayout(new FlowLayout( ));
//Sets the buttons
continueButton = new JButton("Continue");
buttonPanel.add(continueButton);
backButton = new JButton("Back");
buttonPanel.add(backButton);
add(buttonPanel, getConstraints(0,3,3,1,

GridBagConstraints.WEST));
//
//how many night selection box
//
String [] nights = { "1", "2", "3", "4" ,"5" ,"6"
,"7" ,"8", "9", "10", "11", "12", "13"};
//
nightsBox = new JComboBox(nights);
//
add(nightsBox, getConstraints(1,3,1,1,
GridBagConstraints.WEST));
//
//
nightsBox.addActionListener(new
ContinueActionListener());
continueButton.addActionListener(new
ContinueActionListener());
backButton.addActionListener(new
ContinueActionListener());
Border loweredBorder =
BorderFactory.createBevelBorder(BevelBorder.LOWERED);
// radio button panel
JPanel radioPanel = new JPanel();
ButtonGroup typeGroup = new ButtonGroup();
radioPanel.setLayout(new
FlowLayout(FlowLayout.LEFT));
radioPanel.setBorder(BorderFactory.createTitledBorder(loweredBord
er, "Room Type:"));
// single radio button
singleRadioButton = new JRadioButton("Single",
true);
typeGroup.add(singleRadioButton);
radioPanel.add(singleRadioButton);
// double radio button
doubleRadioButton = new JRadioButton("Double");
typeGroup.add(doubleRadioButton);
radioPanel.add(doubleRadioButton);
// suite radio button
suiteRadioButton = new JRadioButton("Suite");
typeGroup.add(suiteRadioButton);
radioPanel.add(suiteRadioButton);
add(radioPanel, getConstraints(0,0,3,1,
GridBagConstraints.WEST));
}
private GridBagConstraints getConstraints(int gridx, int
gridy,int gridwidth, int gridheight, int anchor)
{
GridBagConstraints c = new GridBagConstraints();

c.insets = new Insets(2, 5, 2, 5);


c.ipadx = 0;
c.ipady = 0;
c.gridx = gridx;
c.gridy = gridy;
c.gridwidth = gridwidth;
c.gridheight = gridheight;
c.anchor = anchor;
return c;
}
}
//GUI for confirming reservation (below)
class ConfirmationFrame extends JFrame
{
public ConfirmationFrame()
{
setTitle("Confirmation Page");
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
JPanel panel = new ConfirmationPanel();
this.add(panel);
this.setSize(400, 200);
}
}
class ConfirmationPanel extends JPanel
{
private JButton confirmButton,
backButton;
private JTextArea display;
private class ConfirmActionListener implements
ActionListener
{
public void actionPerformed(ActionEvent e)
{
Object source = e.getSource();
if(source==confirmButton)
{
MainMenuPanel.alteration(MainMenuPanel.getRoom(),MainMenuPa
nel.getTime(), MainMenuPanel.getCost());
JOptionPane.showMessageDialog(null,
"Reservation has been made.");
JFrame loop = new ChoiceFrame();
loop.setVisible(true);
backToMain();

}
else if(source==backButton)
{
backToMain();
}
}
}
public void backToMain()
{
(SwingUtilities.getWindowAncestor(this)).dispose();
}
public ConfirmationPanel()
{
this.setLayout(new GridBagLayout());
JPanel buttonPanel = new JPanel( );
buttonPanel.setLayout(new FlowLayout( ));
display = new JTextArea(5,20);
display.setEditable(false);
display.append("Room:
"+MainMenuPanel.getRoom()+"\n");
display.append("Number of nights:"
+MainMenuPanel.getTime()+"\n");
display.append("Cost: $"+MainMenuPanel.getCost());
add(display, getConstraints(0,0,3,1,
GridBagConstraints.WEST));
//Sets the buttons
confirmButton = new JButton("Confirm");
buttonPanel.add(confirmButton);
backButton = new JButton("Back");
buttonPanel.add(backButton);
add(buttonPanel, getConstraints(0,3,3,1,
GridBagConstraints.WEST));
confirmButton.addActionListener(new
ConfirmActionListener());
backButton.addActionListener(new
ConfirmActionListener());
}
private GridBagConstraints getConstraints(int gridx, int
gridy,int gridwidth, int gridheight, int anchor)
{
GridBagConstraints c = new GridBagConstraints();
c.insets = new Insets(2, 5, 2, 5);
c.ipadx = 0;
c.ipady = 0;

c.gridx = gridx;
c.gridy = gridy;
c.gridwidth = gridwidth;
c.gridheight = gridheight;
c.anchor = anchor;
return c;
}
}
//GUI for cancelations (below)
class CancelFrame extends JFrame
{
public CancelFrame()
{
setTitle("Cancelations Page");
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
JPanel panel = new CancelPanel();
this.add(panel);
this.setSize(400, 200);
}
}
class CancelPanel extends JPanel
{
private JButton confirmButton,
backButton;
private JTextArea display;
private class ConfirmActionListener implements
ActionListener
{
public void actionPerformed(ActionEvent e)
{
Object source = e.getSource();
if(source==confirmButton)
{
MainMenuPanel.cancelation();
MainMenuPanel.alteration("No room
reserved", 0, 0);
JOptionPane.showMessageDialog(null,
"Reservation has been canceled.");
JFrame loop = new ChoiceFrame();
loop.setVisible(true);
backToMain();
}
else if(source==backButton)

{
JFrame loop = new ChoiceFrame();
loop.setVisible(true);
backToMain();
}
}
}
public void backToMain()
{
(SwingUtilities.getWindowAncestor(this)).dispose();
}
public CancelPanel()
{
this.setLayout(new GridBagLayout());
JPanel buttonPanel = new JPanel( );
buttonPanel.setLayout(new FlowLayout( ));
display = new JTextArea(5,20);
display.setEditable(false);
display.append(MainMenuPanel.retrieval());
add(display, getConstraints(0,0,3,1,
GridBagConstraints.WEST));
//Sets the buttons
confirmButton = new JButton("Confirm");
buttonPanel.add(confirmButton);
backButton = new JButton("Back");
buttonPanel.add(backButton);
add(buttonPanel, getConstraints(0,3,3,1,
GridBagConstraints.WEST));
confirmButton.addActionListener(new
ConfirmActionListener());
backButton.addActionListener(new
ConfirmActionListener());
}
private GridBagConstraints getConstraints(int gridx,
int gridy,int gridwidth, int gridheight, int anchor)
{
GridBagConstraints c = new GridBagConstraints();
c.insets = new Insets(2, 5, 2, 5);
c.ipadx = 0;
c.ipady = 0;
c.gridx = gridx;
c.gridy = gridy;
c.gridwidth = gridwidth;

c.gridheight = gridheight;
c.anchor = anchor;
return c;
}
}
//GUI for viewing profile information
class ViewingFrame extends JFrame
{
public ViewingFrame()
{
setTitle("Account Information");
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
JPanel panel = new ViewingPanel();
this.add(panel);
this.setSize(400, 200);
}
}
class ViewingPanel extends JPanel
{
private JButton confirmButton,
backButton;
private JTextArea display;
private class ConfirmActionListener implements
ActionListener
{
public void actionPerformed(ActionEvent e)
{
Object source = e.getSource();
if(source==backButton)
{
JFrame loop = new ChoiceFrame();
loop.setVisible(true);
backToMain();
}
}
}
public void backToMain()
{
(SwingUtilities.getWindowAncestor(this)).dispose();
}
public ViewingPanel()
{
this.setLayout(new GridBagLayout());
JPanel buttonPanel = new JPanel( );
buttonPanel.setLayout(new FlowLayout( ));

display = new JTextArea(5,20);


display.setEditable(false);
display.append(MainMenuPanel.retrieval());
add(display, getConstraints(0,0,3,1,
GridBagConstraints.WEST));
//Sets the buttons
backButton = new JButton("Back");
buttonPanel.add(backButton);
add(buttonPanel, getConstraints(0,3,3,1,
GridBagConstraints.WEST));
backButton.addActionListener(new
ConfirmActionListener());
}
private GridBagConstraints getConstraints(int gridx, int
gridy,int gridwidth, int gridheight, int anchor)
{
GridBagConstraints c = new GridBagConstraints();
c.insets = new Insets(2, 5, 2, 5);
c.ipadx = 0;
c.ipady = 0;
c.gridx = gridx;
c.gridy = gridy;
c.gridwidth = gridwidth;
c.gridheight = gridheight;
c.anchor = anchor;
return c;
}
}
//Window for Password changing (below)
class PasswordFrame extends JFrame
{
public PasswordFrame()
{
setTitle("Password Resetting");
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
JPanel panel = new PasswordPanel();
this.add(panel);
this.setSize(400, 200);
}
}
class PasswordPanel extends JPanel
{
private JButton confirmButton,

backButton;
private JTextField textFieldPrevious,
textFieldNew;
private JLabel previousLabel,
newLabel;
private class PasswordActionListener implements
ActionListener
{
public void actionPerformed(ActionEvent e)
{
Object source = e.getSource();
if(source==confirmButton)
{
if(!textFieldPrevious.getText().equals("")
&& !textFieldNew.getText().equals(""))
{
if(MainMenuPanel.passCheck(textFieldPrevious.getText())==tr
ue)
{
MainMenuPanel.passChanger(textFieldNew.getText());
JOptionPane.showMessageDialog(null, "Password changed
successfully.");
JFrame loop = new ChoiceFrame();
loop.setVisible(true);
backToMain();
}
else
{
JOptionPane.showMessageDialog(null, "Password does not
exist to change.");
}
}
else
{
JOptionPane.showMessageDialog(null,
"All fields must be completed.");
}
}
else if(source==backButton)
{
JFrame loop = new ChoiceFrame();
loop.setVisible(true);

backToMain();
}
}
}
public void backToMain()
{
(SwingUtilities.getWindowAncestor(this)).dispose();
}
public PasswordPanel()
{
this.setLayout(new GridBagLayout());
JPanel textField = new JPanel();
textField.setLayout(new GridLayout(4,4));
JPanel buttonPanel = new JPanel( );
buttonPanel.setLayout(new FlowLayout( ));
//Sets the buttons
confirmButton = new JButton("Submit");
buttonPanel.add(confirmButton);
backButton = new JButton("Cancel");
buttonPanel.add(backButton);
add(buttonPanel, getConstraints(0,3,3,1,
GridBagConstraints.WEST));
confirmButton.addActionListener(new
PasswordActionListener());
backButton.addActionListener(new
PasswordActionListener());
previousLabel = new JLabel("Previous Pass");
add(previousLabel, getConstraints(0,0,3,1,
GridBagConstraints.WEST));
newLabel = new JLabel("New Pass");
add(newLabel, getConstraints(0,1,3,1,
GridBagConstraints.WEST));
textFieldPrevious = new JTextField(8);
add(textFieldPrevious, getConstraints(3,0,3,1,
GridBagConstraints.EAST));
textFieldNew = new JTextField(8);
add(textFieldNew, getConstraints(3,1,3,1,
GridBagConstraints.EAST));
textFieldPrevious.addActionListener(new
PasswordActionListener());
textFieldNew.addActionListener(new

PasswordActionListener());
}
private GridBagConstraints getConstraints(int gridx, int
gridy,int gridwidth, int gridheight, int anchor)
{
GridBagConstraints c = new GridBagConstraints();
c.insets = new Insets(2, 5, 2, 5);
c.ipadx = 0;
c.ipady = 0;
c.gridx = gridx;
c.gridy = gridy;
c.gridwidth = gridwidth;
c.gridheight = gridheight;
c.anchor = anchor;
return c;
}
}
//Adminstator's options page (below)
class OptionsFrame extends JFrame
{
public OptionsFrame()
{
setTitle("Administrative Page");
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
JPanel panel = new OptionsPanel();
this.add(panel);
this.setSize(400, 200);
}
}
class OptionsPanel extends JPanel
{
private JButton editButton,
blockingButton,
viewingButton,
passchangeButton,
logoutButton;
private JTextField textFieldUser,
textFieldPass;
private JLabel userLabel,
passLabel;
// Listener for class Choice's buttons
private class OptionsActionListener implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
Object source = e.getSource();

if(source==editButton)
{
if(MainMenuPanel.existing()==true)
{
JOptionPane.showMessageDialog(null,
"Account already has reservation.");
}
else
{
// goes to reservation window
JFrame caller = new EditFrame();
caller.setVisible(true);
backToMain();
}
}
else if(source==blockingButton)
{
// goes to canceling window
JFrame caller = new BlockFrame();
caller.setVisible(true);
backToMain();
}
else if(source==viewingButton)
{
JFrame caller = new SystemFrame();
caller.setVisible(true);
backToMain();
}
else if(source==logoutButton)
{
backToMain();
}
else
{
JOptionPane.showMessageDialog(null, "Invalid
seleciton.");
}
}
}
public void backToMain()
{
(SwingUtilities.getWindowAncestor(this)).dispose();
}
public OptionsPanel()
{
this.setLayout(new GridBagLayout());
JPanel buttonPanel = new JPanel( );
buttonPanel.setLayout(new FlowLayout( ));

//Sets the buttons


editButton = new JButton("Account Editor");
buttonPanel.add(editButton);
blockingButton = new JButton("Block Account");
buttonPanel.add(blockingButton);
viewingButton = new JButton("Database Viewing");
buttonPanel.add(viewingButton);
logoutButton = new JButton("Log Out");
buttonPanel.add(logoutButton);
editButton.addActionListener(new
OptionsActionListener());
blockingButton.addActionListener(new
OptionsActionListener());
viewingButton.addActionListener(new
OptionsActionListener());
logoutButton.addActionListener(new
OptionsActionListener());
//Layout for the JFrame of the Main Window
GridBagConstraints gc = new GridBagConstraints();
gc.gridx = 0;
gc.gridy = 0;
gc.anchor = GridBagConstraints.CENTER;
this.add(editButton, gc);
gc.gridy = 1;
this.add(blockingButton, gc);
gc.gridy = 2;
this.add(viewingButton, gc);
gc.gridy = 3;
this.add(logoutButton, gc);
}
}
//Adminstator's viewing page (below)
class SystemFrame extends JFrame
{
public SystemFrame()
{
setTitle("Database");
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
JPanel panel = new SystemCheckPanel();
this.add(panel);
this.setSize(400, 200);
}
}

class SystemCheckPanel extends JPanel


{
private JButton backButton;
private JTextArea display;
private class SystemCheckActionListener implements
ActionListener
{
public void actionPerformed(ActionEvent e)
{
Object source = e.getSource();
if(source==backButton)
{
JFrame loop = new OptionsFrame();
loop.setVisible(true);
backToMain();
}
else
{
JOptionPane.showMessageDialog(null,
"Invalid selection.");
}
}
}
public void backToMain()
{
(SwingUtilities.getWindowAncestor(this)).dispose();
}
public SystemCheckPanel()
{
this.setLayout(new GridBagLayout());
JPanel buttonPanel = new JPanel( );
buttonPanel.setLayout(new FlowLayout( ));
display = new JTextArea(5,20);
display.setEditable(false);
display.append(MainMenuPanel.grab());
add(display, getConstraints(0,0,3,1,
GridBagConstraints.WEST));
//Sets the buttons
backButton = new JButton("Back");
buttonPanel.add(backButton);
add(buttonPanel, getConstraints(0,3,3,1,
GridBagConstraints.WEST));
backButton.addActionListener(new

SystemCheckActionListener());
}
private GridBagConstraints getConstraints(int gridx, int
gridy,int gridwidth, int gridheight, int anchor)
{
GridBagConstraints c = new GridBagConstraints();
c.insets = new Insets(2, 5, 2, 5);
c.ipadx = 0;
c.ipady = 0;
c.gridx = gridx;
c.gridy = gridy;
c.gridwidth = gridwidth;
c.gridheight = gridheight;
c.anchor = anchor;
return c;
}
}
//GUI for blocking an account
class BlockFrame extends JFrame
{
public BlockFrame()
{
setTitle("Account Blocking");
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
JPanel panel = new BlockPanel();
this.add(panel);
this.setSize(400, 200);
}
}
class BlockPanel extends JPanel
{
private JButton confirmButton,
backButton;
private JTextField textFieldAccount;
private JLabel usernameLabel;
private class BlockActionListener implements
ActionListener
{
public void actionPerformed(ActionEvent e)
{
Object source = e.getSource();
if(source==confirmButton)
{
if(!textFieldAccount.getText().equals(""))
{
if(MainMenuPanel.checker(textFieldAccount.getText())==false

)
{
JOptionPane.showMessageDialog(null,
"Account does not exist.");
}
else
{
MainMenuPanel.blocker();
JOptionPane.showMessageDialog(null, "Account has been
blocked.");
JFrame loop = new
OptionsFrame();
loop.setVisible(true);
backToMain();
}
}
else
{
JOptionPane.showMessageDialog(null,
"Username must be entered.");
}
}
else if(source==backButton)
{
JFrame loop = new OptionsFrame();
loop.setVisible(true);
backToMain();
}
}
}
public void backToMain()
{
(SwingUtilities.getWindowAncestor(this)).dispose();
}
public BlockPanel()
{
this.setLayout(new GridBagLayout());
JPanel textField = new JPanel();
textField.setLayout(new GridLayout(4,4));
JPanel buttonPanel = new JPanel( );
buttonPanel.setLayout(new FlowLayout( ));
//Sets the buttons
confirmButton = new JButton("Confirm");
buttonPanel.add(confirmButton);

backButton = new JButton("Back");


buttonPanel.add(backButton);
add(buttonPanel, getConstraints(0,3,3,1,
GridBagConstraints.WEST));
confirmButton.addActionListener(new
BlockActionListener());
backButton.addActionListener(new BlockActionListener());
usernameLabel = new JLabel("Username");
add(usernameLabel, getConstraints(0,0,3,1,
GridBagConstraints.WEST));
textFieldAccount = new JTextField(8);
add(textFieldAccount, getConstraints(3,0,3,1,
GridBagConstraints.EAST));
textFieldAccount.addActionListener(new
BlockActionListener());
}
private GridBagConstraints getConstraints(int gridx, int
gridy,int gridwidth, int gridheight, int anchor)
{
GridBagConstraints c = new GridBagConstraints();
c.insets = new Insets(2, 5, 2, 5);
c.ipadx = 0;
c.ipady = 0;
c.gridx = gridx;
c.gridy = gridy;
c.gridwidth = gridwidth;
c.gridheight = gridheight;
c.anchor = anchor;
return c;
}
}
//GUI for admin editting
class EditFrame extends JFrame
{
public EditFrame()
{
setTitle("Account Editting");
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
JPanel panel = new EditPanel();
this.add(panel);
this.setSize(400, 200);
}
}

class EditPanel extends JPanel


{
private JButton confirmButton,
backButton;
private JTextField textFieldAccount;
private JLabel usernameLabel;
private class EditActionListener implements
ActionListener
{
public void actionPerformed(ActionEvent e)
{
Object source = e.getSource();
if(source==confirmButton)
{
if(!textFieldAccount.getText().equals(""))
{
if(MainMenuPanel.blockCheck(textFieldAccount.getText())==tr
ue)
{
JOptionPane.showMessageDialog(null,
"This account has been blocked.");
}
else
if(MainMenuPanel.checker(textFieldAccount.getText())==false)
{
JOptionPane.showMessageDialog(null,
"Account does not exist.");
}
else
{
JFrame go = new ChoiceFrame();
go.setVisible(true);
backToMain();
}
}
else
{
JOptionPane.showMessageDialog(null,
"Username must be entered.");
}
}
else if(source==backButton)
{
JFrame loop = new OptionsFrame();
loop.setVisible(true);
backToMain();
}

}
}
public void backToMain()
{
(SwingUtilities.getWindowAncestor(this)).dispose();
}
public EditPanel()
{
this.setLayout(new GridBagLayout());
JPanel textField = new JPanel();
textField.setLayout(new GridLayout(4,4));
JPanel buttonPanel = new JPanel( );
buttonPanel.setLayout(new FlowLayout( ));
//Sets the buttons
confirmButton = new JButton("Edit");
buttonPanel.add(confirmButton);
backButton = new JButton("Back");
buttonPanel.add(backButton);
add(buttonPanel, getConstraints(0,3,3,1,
GridBagConstraints.WEST));
confirmButton.addActionListener(new
EditActionListener());
backButton.addActionListener(new EditActionListener());
usernameLabel = new JLabel("Username");
add(usernameLabel, getConstraints(0,0,3,1,
GridBagConstraints.WEST));
textFieldAccount = new JTextField(8);
add(textFieldAccount, getConstraints(3,0,3,1,
GridBagConstraints.EAST));
textFieldAccount.addActionListener(new
EditActionListener());
}
private GridBagConstraints getConstraints(int gridx, int
gridy,int gridwidth, int gridheight, int anchor)
{
GridBagConstraints c = new GridBagConstraints();
c.insets = new Insets(2, 5, 2, 5);
c.ipadx = 0;
c.ipady = 0;
c.gridx = gridx;
c.gridy = gridy;
c.gridwidth = gridwidth;
c.gridheight = gridheight;

c.anchor = anchor;
return c;
}
}

You might also like