Advertisement
Guest User

Untitled

a guest
Dec 14th, 2019
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.44 KB | None | 0 0
  1. import java.awt.GraphicsConfiguration;
  2. import javax.swing.JFrame;
  3. import java.awt.Color;
  4. import javax.swing.*;
  5. import java.awt.event.ActionEvent;
  6. import java.awt.event.ActionListener;
  7. import java.awt.event.MouseAdapter;
  8. import java.awt.event.MouseEvent;
  9. import javax.swing.JButton;
  10. import javax.swing.JLabel;
  11. import javax.swing.JRadioButton;
  12. import javax.swing.ButtonGroup;
  13. import javax.swing.JTable;
  14. import javax.swing.JScrollPane;
  15. import javax.swing.JTextField;
  16. import javax.swing.JCheckBox;
  17. import javax.swing.table.DefaultTableModel;
  18.  
  19. public class FinalsProject
  20. {
  21. static GraphicsConfiguration gc;
  22. static DefaultTableModel model = new DefaultTableModel();
  23. static JTable table = new JTable();
  24. static String roomType = "";
  25. public static void main(String[] args)
  26. {
  27. //Jframe Title
  28. JFrame frame = new JFrame(gc);
  29. frame.setTitle("Hotel Reservation");
  30. frame.setSize(300, 300);
  31. frame.setVisible(true);
  32. frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  33. frame.setLayout(null);
  34.  
  35. //Columns for Inputs
  36. Object[] columns = {"name", "contact no.", "days of staying", "roomtype"};
  37. final Object[] row = new Object[4];
  38. model.setColumnIdentifiers(columns);
  39. table.setModel(model);
  40. table.setRowHeight(30);
  41. table.setBackground(Color.black);
  42. table.setForeground(Color.white);
  43.  
  44. //Buttons
  45. JButton b = new JButton("Check in");
  46. b.setBounds(100, 350, 140, 40);
  47. JButton b1 = new JButton("Check out");
  48. b1.setBounds(100, 415, 140, 40);
  49. JButton b2 = new JButton("update");
  50. b2.setBounds(100, 470, 140, 40);
  51. JButton b3 = new JButton("Get Reciept");
  52. b3.setBounds(100, 535, 140, 40);
  53. JButton exit = new JButton("Exit");
  54. exit.setBounds(1100,575, 140, 40);
  55.  
  56. //Labels
  57. JLabel name = new JLabel();
  58. JLabel cn = new JLabel();
  59. JLabel day = new JLabel();
  60. JLabel rt = new JLabel();
  61. JLabel ordi = new JLabel();
  62. JLabel spe = new JLabel();
  63. JLabel lux = new JLabel();
  64.  
  65. //Labels
  66. name.setText("Enter FullName :");
  67. name.setBounds(10, 10, 100, 100);
  68.  
  69. cn.setText("Contact Number:");
  70. cn.setBounds(10, 70, 100, 100);
  71.  
  72. day.setText("Days to Stay in:");
  73. day.setBounds(10, 130, 100, 100);
  74.  
  75. rt.setText("Room Type:");
  76. rt.setBounds(10, 189, 100, 100);
  77.  
  78. ordi.setText("(PHP 750/day)");
  79. ordi.setBounds(180, 220, 120, 40);
  80. frame.add(ordi);
  81.  
  82. spe.setText("(PHP 1000/day)");
  83. spe.setBounds(180, 250, 120, 40);
  84. frame.add(spe);
  85.  
  86. lux.setText("(PHP 1500/day)");
  87. lux.setBounds(180, 280, 120, 40);
  88. frame.add(lux);
  89.  
  90. //TextFields
  91. final JTextField name1 = new JTextField("");
  92. name1.setBounds(110, 50, 130, 30);
  93.  
  94. final JTextField cn1 = new JTextField("");
  95. cn1.setBounds(110, 110, 130, 30);
  96.  
  97. final JTextField days = new JTextField("");
  98. days.setBounds(110, 170, 130, 30);
  99.  
  100. table.setBounds(270, 50, 1000, 500);
  101.  
  102. //Frames Adding
  103. frame.add(name);
  104. frame.add(name1);
  105.  
  106. frame.add(cn);
  107. frame.add(cn1);
  108.  
  109. frame.add(day);
  110. frame.add(days);
  111.  
  112. frame.add(rt);
  113. frame.add(table);
  114.  
  115. frame.add(b);
  116. frame.add(b1);
  117.  
  118. frame.add(b2);
  119. frame.add(b3);
  120. frame.add(exit);
  121.  
  122. //RadioButtons
  123. final JRadioButton Ordinary;
  124. final JRadioButton Special;
  125. final JRadioButton Luxury;
  126. Ordinary = new JRadioButton("Ordinary");
  127. Special = new JRadioButton("Special");
  128. Luxury = new JRadioButton("Luxury");
  129.  
  130. ButtonGroup bg = new ButtonGroup();
  131. bg.add(Ordinary);
  132. bg.add(Special);
  133. bg.add(Luxury);
  134.  
  135. frame.add(Ordinary);
  136. Ordinary.setBounds(105, 220, 75, 40);
  137. frame.add(Special);
  138. Special.setBounds(105, 250, 75, 40);
  139. frame.add(Luxury);
  140. Luxury.setBounds(105, 280, 75, 40);
  141.  
  142. Ordinary.setSelected(false);
  143. Special.setSelected(false);
  144. Luxury.setSelected(false);
  145.  
  146. //Action Listener for Check in
  147. b.addActionListener(new ActionListener(){
  148. public void actionPerformed(ActionEvent e){
  149. row[0]=name1.getText();
  150. row[1]=cn1.getText();
  151. row[2]=days.getText();
  152. if(Ordinary.isSelected())
  153. {
  154. row[3] = "Ordinary";
  155. }
  156. else if(Special.isSelected())
  157. {
  158. row[3] = "Special";
  159. }
  160. else if(Luxury.isSelected())
  161. {
  162. row[3] = "Luxury";
  163. }
  164. else
  165. {
  166. JOptionPane.showMessageDialog(null, "PLEASE SELECT TYPE OF ROOM");
  167. }
  168.  
  169. model.addRow(row);
  170. }
  171.  
  172. });
  173. //ActionListener for Check out
  174. b1.addActionListener(new ActionListener(){
  175. public void actionPerformed(ActionEvent e){
  176.  
  177. int i = table.getSelectedRow();
  178. if(i>=0){
  179. model.removeRow(i);
  180. }
  181. }
  182. });
  183. //MouseListener for Update
  184. table.addMouseListener(new MouseAdapter(){
  185.  
  186. public void mouseClicked(MouseEvent e){
  187. int i = table.getSelectedRow();
  188. name1.setText(model.getValueAt(i,0).toString());
  189. cn1.setText(model.getValueAt(i,1).toString());
  190. days.setText(model.getValueAt(i,2).toString());
  191. roomType = model.getValueAt(i,3).toString();
  192. }
  193. });
  194. //ActionListener for RadioButtons Roomtype
  195. b2.addActionListener(new ActionListener(){
  196. public void actionPerformed(ActionEvent e){
  197. int i = table.getSelectedRow();
  198.  
  199. if(i>=0)
  200. {
  201. model.setValueAt(name1.getText(), i, 0);
  202. model.setValueAt(cn1.getText(), i, 1);
  203. model.setValueAt(days.getText(), i, 2);
  204. if (Ordinary.isSelected())
  205. {
  206. model.setValueAt("Ordinary", i, 3);
  207. }
  208. else if (Special.isSelected())
  209. {
  210. model.setValueAt("Special", i, 3);
  211. }
  212. else if (Luxury.isSelected())
  213. {
  214. model.setValueAt("Luxury", i, 3);
  215. }
  216. else
  217. {
  218. JOptionPane.showMessageDialog(null, "PLEASE SELECT TYPE OF ROOM");
  219. }
  220.  
  221. }
  222. }
  223. });
  224. //Declaring RoomPrices
  225. b3.addActionListener(new ActionListener(){
  226. public void actionPerformed(ActionEvent e) {
  227. if(e.getSource() == b3)
  228. {
  229. String namex=name1.getText();
  230. String numx=cn1.getText();
  231. String dayx=days.getText();
  232. int dayxx=Integer.parseInt(dayx);
  233. int result = 0;
  234. int roomPrice = 0;
  235. if(roomType.equals("Ordinary"))
  236. {
  237. roomPrice = 750;
  238. }
  239. else if(roomType.equals("Special"))
  240. {
  241. roomPrice = 1000;
  242. }
  243. else if(roomType.equals("Luxury"))
  244. {
  245. roomPrice = 1500;
  246. }
  247. result = roomPrice * dayxx; //Computation
  248. //Receipt
  249. JOptionPane.showMessageDialog(null," Your Receipt\nFullName: "+namex+"\nContact Number: "+numx+"\nDay(s) to Stay in: "+dayx+"\nYour Price is: "+result);
  250. }
  251. else
  252. {
  253. }
  254. }
  255. });
  256. //Exit/close Program
  257. exit.addActionListener(new ActionListener() {
  258. public void actionPerformed(ActionEvent e)
  259. {
  260. System.exit(0);
  261. }
  262. });
  263. }
  264. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement