Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.GraphicsConfiguration;
- import javax.swing.JFrame;
- import java.awt.Color;
- import javax.swing.*;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import java.awt.event.MouseAdapter;
- import java.awt.event.MouseEvent;
- import javax.swing.JButton;
- import javax.swing.JLabel;
- import javax.swing.JRadioButton;
- import javax.swing.ButtonGroup;
- import javax.swing.JTable;
- import javax.swing.JScrollPane;
- import javax.swing.JTextField;
- import javax.swing.JCheckBox;
- import javax.swing.table.DefaultTableModel;
- public class FinalsProject
- {
- static GraphicsConfiguration gc;
- static DefaultTableModel model = new DefaultTableModel();
- static JTable table = new JTable();
- static String roomType = "";
- public static void main(String[] args)
- {
- //Jframe Title
- JFrame frame = new JFrame(gc);
- frame.setTitle("Hotel Reservation");
- frame.setSize(300, 300);
- frame.setVisible(true);
- frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- frame.setLayout(null);
- //Columns for Inputs
- Object[] columns = {"name", "contact no.", "days of staying", "roomtype"};
- final Object[] row = new Object[4];
- model.setColumnIdentifiers(columns);
- table.setModel(model);
- table.setRowHeight(30);
- table.setBackground(Color.black);
- table.setForeground(Color.white);
- //Buttons
- JButton b = new JButton("Check in");
- b.setBounds(100, 350, 140, 40);
- JButton b1 = new JButton("Check out");
- b1.setBounds(100, 415, 140, 40);
- JButton b2 = new JButton("update");
- b2.setBounds(100, 470, 140, 40);
- JButton b3 = new JButton("Get Reciept");
- b3.setBounds(100, 535, 140, 40);
- JButton exit = new JButton("Exit");
- exit.setBounds(1100,575, 140, 40);
- //Labels
- JLabel name = new JLabel();
- JLabel cn = new JLabel();
- JLabel day = new JLabel();
- JLabel rt = new JLabel();
- JLabel ordi = new JLabel();
- JLabel spe = new JLabel();
- JLabel lux = new JLabel();
- //Labels
- name.setText("Enter FullName :");
- name.setBounds(10, 10, 100, 100);
- cn.setText("Contact Number:");
- cn.setBounds(10, 70, 100, 100);
- day.setText("Days to Stay in:");
- day.setBounds(10, 130, 100, 100);
- rt.setText("Room Type:");
- rt.setBounds(10, 189, 100, 100);
- ordi.setText("(PHP 750/day)");
- ordi.setBounds(180, 220, 120, 40);
- frame.add(ordi);
- spe.setText("(PHP 1000/day)");
- spe.setBounds(180, 250, 120, 40);
- frame.add(spe);
- lux.setText("(PHP 1500/day)");
- lux.setBounds(180, 280, 120, 40);
- frame.add(lux);
- //TextFields
- final JTextField name1 = new JTextField("");
- name1.setBounds(110, 50, 130, 30);
- final JTextField cn1 = new JTextField("");
- cn1.setBounds(110, 110, 130, 30);
- final JTextField days = new JTextField("");
- days.setBounds(110, 170, 130, 30);
- table.setBounds(270, 50, 1000, 500);
- //Frames Adding
- frame.add(name);
- frame.add(name1);
- frame.add(cn);
- frame.add(cn1);
- frame.add(day);
- frame.add(days);
- frame.add(rt);
- frame.add(table);
- frame.add(b);
- frame.add(b1);
- frame.add(b2);
- frame.add(b3);
- frame.add(exit);
- //RadioButtons
- final JRadioButton Ordinary;
- final JRadioButton Special;
- final JRadioButton Luxury;
- Ordinary = new JRadioButton("Ordinary");
- Special = new JRadioButton("Special");
- Luxury = new JRadioButton("Luxury");
- ButtonGroup bg = new ButtonGroup();
- bg.add(Ordinary);
- bg.add(Special);
- bg.add(Luxury);
- frame.add(Ordinary);
- Ordinary.setBounds(105, 220, 75, 40);
- frame.add(Special);
- Special.setBounds(105, 250, 75, 40);
- frame.add(Luxury);
- Luxury.setBounds(105, 280, 75, 40);
- Ordinary.setSelected(false);
- Special.setSelected(false);
- Luxury.setSelected(false);
- //Action Listener for Check in
- b.addActionListener(new ActionListener(){
- public void actionPerformed(ActionEvent e){
- row[0]=name1.getText();
- row[1]=cn1.getText();
- row[2]=days.getText();
- if(Ordinary.isSelected())
- {
- row[3] = "Ordinary";
- }
- else if(Special.isSelected())
- {
- row[3] = "Special";
- }
- else if(Luxury.isSelected())
- {
- row[3] = "Luxury";
- }
- else
- {
- JOptionPane.showMessageDialog(null, "PLEASE SELECT TYPE OF ROOM");
- }
- model.addRow(row);
- }
- });
- //ActionListener for Check out
- b1.addActionListener(new ActionListener(){
- public void actionPerformed(ActionEvent e){
- int i = table.getSelectedRow();
- if(i>=0){
- model.removeRow(i);
- }
- }
- });
- //MouseListener for Update
- table.addMouseListener(new MouseAdapter(){
- public void mouseClicked(MouseEvent e){
- int i = table.getSelectedRow();
- name1.setText(model.getValueAt(i,0).toString());
- cn1.setText(model.getValueAt(i,1).toString());
- days.setText(model.getValueAt(i,2).toString());
- roomType = model.getValueAt(i,3).toString();
- }
- });
- //ActionListener for RadioButtons Roomtype
- b2.addActionListener(new ActionListener(){
- public void actionPerformed(ActionEvent e){
- int i = table.getSelectedRow();
- if(i>=0)
- {
- model.setValueAt(name1.getText(), i, 0);
- model.setValueAt(cn1.getText(), i, 1);
- model.setValueAt(days.getText(), i, 2);
- if (Ordinary.isSelected())
- {
- model.setValueAt("Ordinary", i, 3);
- }
- else if (Special.isSelected())
- {
- model.setValueAt("Special", i, 3);
- }
- else if (Luxury.isSelected())
- {
- model.setValueAt("Luxury", i, 3);
- }
- else
- {
- JOptionPane.showMessageDialog(null, "PLEASE SELECT TYPE OF ROOM");
- }
- }
- }
- });
- //Declaring RoomPrices
- b3.addActionListener(new ActionListener(){
- public void actionPerformed(ActionEvent e) {
- if(e.getSource() == b3)
- {
- String namex=name1.getText();
- String numx=cn1.getText();
- String dayx=days.getText();
- int dayxx=Integer.parseInt(dayx);
- int result = 0;
- int roomPrice = 0;
- if(roomType.equals("Ordinary"))
- {
- roomPrice = 750;
- }
- else if(roomType.equals("Special"))
- {
- roomPrice = 1000;
- }
- else if(roomType.equals("Luxury"))
- {
- roomPrice = 1500;
- }
- result = roomPrice * dayxx; //Computation
- //Receipt
- JOptionPane.showMessageDialog(null," Your Receipt\nFullName: "+namex+"\nContact Number: "+numx+"\nDay(s) to Stay in: "+dayx+"\nYour Price is: "+result);
- }
- else
- {
- }
- }
- });
- //Exit/close Program
- exit.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e)
- {
- System.exit(0);
- }
- });
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement