Advertisement
Guest User

Untitled

a guest
Oct 10th, 2018
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.30 KB | None | 0 0
  1.  
  2. import java.awt.Container;
  3.  
  4. import javax.swing.*;
  5. import java.io.*;
  6. import java.awt.*;
  7. import java.awt.event.*;
  8.  
  9. import java.awt.GridLayout;
  10. import java.awt.event.ActionEvent;
  11. import java.awt.event.ActionListener;
  12.  
  13. import javax.swing.JButton;
  14. import javax.swing.JFrame;
  15. import javax.swing.JLabel;
  16. import javax.swing.JPanel;
  17. import javax.swing.JTextField;
  18. import javax.swing.SwingConstants;
  19.  
  20.  
  21. public class Lab5 extends JFrame {
  22.  
  23.  
  24.  
  25. private static final int WIDTH=400;
  26. private static final int HEIGHT=500;
  27. JLabel Welcome, Prompt, First, Last, Email, Phone, Credit, Label1, Label2, Label3, Label4, Booking;
  28. JTextField F, L, E, P, C, L3, L4;
  29. JButton Button1, Button2, Button3, Button4, Book;
  30. JLabel S1, S2, S3, S4, S5, S6, Fees;
  31. String a, b;
  32.  
  33.  
  34. AbuDhabiHandler adhandler;
  35. DubaiHandler dxbhandler;
  36. LondonHandler lhandler;
  37. ParisHandler phandler;
  38. BookHandler bhandler;
  39.  
  40.  
  41. public Lab5()
  42. {
  43.  
  44.  
  45. adhandler = new AbuDhabiHandler();
  46. dxbhandler = new DubaiHandler();
  47. lhandler = new LondonHandler();
  48. phandler = new ParisHandler();
  49. bhandler = new BookHandler();
  50.  
  51.  
  52.  
  53.  
  54. setTitle("Flight Booking Application");
  55. Container Pane=getContentPane();
  56. Pane.setLayout(new GridLayout(0,2));
  57. Welcome=new JLabel("Welcome to KU Flight booking");
  58. Prompt=new JLabel("Enter Your Personal Information");
  59. First= new JLabel("First Name:", SwingConstants.LEFT);
  60. Last= new JLabel("Last Name:", SwingConstants.LEFT);
  61. Email= new JLabel("Email Address:", SwingConstants.LEFT);
  62. Phone= new JLabel("Phone Number:", SwingConstants.LEFT);
  63. Credit= new JLabel("Credit Card Number", SwingConstants.LEFT);
  64. Label1= new JLabel("Depart from", SwingConstants.LEFT);
  65. Label2= new JLabel("Depart to", SwingConstants.LEFT);
  66. Label3= new JLabel("Departure date", SwingConstants.LEFT);
  67. Label4= new JLabel("Return date", SwingConstants.LEFT);
  68. Booking= new JLabel("Booking Fees", SwingConstants.LEFT);
  69. Button1 = new JButton("Abu Dhabi");
  70. Button2 = new JButton("Dubai");
  71. Button3 = new JButton("London");
  72. Button4 = new JButton("Paris");
  73. Book = new JButton("Book");
  74. F=new JTextField(10);
  75. L=new JTextField(10);
  76. E=new JTextField(10);
  77. P=new JTextField(10);
  78. C=new JTextField(10);
  79. L3=new JTextField(10);
  80. L4=new JTextField(10);
  81.  
  82. S1 = new JLabel (" ");
  83. S2 = new JLabel (" ");
  84. S3 = new JLabel (" ");
  85. S4 = new JLabel (" ");
  86. S5 = new JLabel (" ");
  87. S6 = new JLabel (" ");
  88. Fees = new JLabel (" ");
  89.  
  90.  
  91. Button1.setEnabled(true);
  92. Button2.setEnabled(true);
  93. Button3.setEnabled(false);
  94. Button4.setEnabled(false);
  95. Book.setEnabled(false);
  96. L3.setEnabled(false);
  97. L4.setEnabled(false);
  98.  
  99.  
  100.  
  101. Button1.addActionListener(adhandler);
  102. Button2.addActionListener(dxbhandler);
  103. Button3.addActionListener(lhandler);
  104. Button4.addActionListener(phandler);
  105. Book.addActionListener(bhandler);
  106.  
  107.  
  108. Pane.add(S1);
  109. Pane.add(Welcome);
  110. Pane.add(Prompt);
  111. Pane.add(S2);
  112. Pane.add(First);
  113. Pane.add(F);
  114. Pane.add(Last);
  115. Pane.add(L);
  116. Pane.add(Email);
  117. Pane.add(E);
  118. Pane.add(Phone);
  119. Pane.add(P);
  120. Pane.add(Credit);
  121. Pane.add(C);
  122. Pane.add(Label1);
  123. Pane.add(S3);
  124. Pane.add(Button1);
  125. Pane.add(Button2);
  126. Pane.add(Label2);
  127. Pane.add(S4);
  128. Pane.add(Button3);
  129. Pane.add(Button4);
  130. Pane.add(Label3);
  131. Pane.add(L3);
  132. Pane.add(Label4);
  133. Pane.add(L4);
  134. Pane.add(Booking);
  135. Pane.add(Fees);
  136. Pane.add(S5);
  137. Pane.add(S6);
  138. Pane.add(Book);
  139.  
  140.  
  141. setSize(WIDTH, HEIGHT);
  142. setDefaultCloseOperation(EXIT_ON_CLOSE);
  143. setVisible(true);
  144.  
  145. }
  146.  
  147. private class AbuDhabiHandler implements ActionListener {
  148.  
  149. @Override
  150. public void actionPerformed(ActionEvent e) {
  151. if (F.getText().equals("") || L.getText().equals("") || E.getText().equals("") || P.getText().equals("") || C.getText().equals("")) {
  152. JOptionPane.showMessageDialog(null, "You have left an empty Text field", "message", JOptionPane.INFORMATION_MESSAGE);
  153. }else {
  154. Button3.setEnabled(true);
  155. Button4.setEnabled(true);
  156. Button2.setEnabled(false);
  157. a = "Abu Dhabi";
  158. }
  159.  
  160. }
  161.  
  162. }
  163. private class DubaiHandler implements ActionListener {
  164.  
  165. @Override
  166. public void actionPerformed(ActionEvent arg0) {
  167. if (F.getText().equals("") || L.getText().equals("") || E.getText().equals("") || P.getText().equals("") || C.getText().equals("")) {
  168. JOptionPane.showMessageDialog(null, "You have left an empty Text field", "message", JOptionPane.INFORMATION_MESSAGE);
  169.  
  170. }else
  171. { Button1.setEnabled(false); Button3.setEnabled(true); Button4.setEnabled(true); a = "Dubai";
  172.  
  173. }
  174.  
  175. }
  176.  
  177. }
  178. private class LondonHandler implements ActionListener {
  179.  
  180. @Override
  181. public void actionPerformed(ActionEvent arg0) {
  182. Button4.setEnabled(false);
  183. L3.setEnabled(true);
  184. L4.setEnabled(true);
  185. Book.setEnabled(true);
  186. b = "London";
  187. if (a.equals("Abu Dhabi")) {
  188. if(b.equals("London"))
  189. Fees.setText("7000 AED");
  190. else
  191. Fees.setText("7500 AED");
  192.  
  193. }else {
  194. if(b.equals("London"))
  195. Fees.setText("9000 AED");
  196. else
  197. Fees.setText("10000 AED");
  198.  
  199. }
  200.  
  201. }
  202.  
  203. }
  204. private class ParisHandler implements ActionListener {
  205.  
  206. @Override
  207. public void actionPerformed(ActionEvent arg0) {
  208. Button3.setEnabled(false);
  209. L3.setEnabled(true);
  210. L4.setEnabled(true);
  211. Book.setEnabled(true);
  212. b = "Paris";
  213. if (a.equals("Abu Dhabi")) {
  214. if(b.equals("London"))
  215. Fees.setText("7000 AED");
  216. else
  217. Fees.setText("7500 AED");
  218. }else{
  219. if(b.equals("London"))
  220. Fees.setText("9000 AED");
  221. else
  222. Fees.setText("10000 AED");
  223.  
  224. }
  225. }
  226. }
  227.  
  228. private class BookHandler implements ActionListener {
  229.  
  230. @Override
  231. public void actionPerformed(ActionEvent arg0) {
  232. if (L3.getText().equals("") || L4.getText().equals("")) {
  233. JOptionPane.showMessageDialog(null, "You have left an empty Text field", "message", JOptionPane.INFORMATION_MESSAGE);
  234.  
  235. }else{
  236. PrintWriter outfile;
  237. try {
  238. outfile = new PrintWriter("receipt.txt");
  239. outfile.print("Dear " + F.getText()+" "+Last.getText() +"\nEmail: "+ E.getText()+"\nPhone number:" + P.getText()+"\nYour booking have been confirmed with the following information\nDepatrure from "+a+" on "+L3.getText() +"\nDestinaion is: "+ b+"\n" + "Return date to your city is : "+L4.getText()+"\nTicket fees are "+Fees.getText()+"\nYour credit card "+C.getText()+" was used to pay for this ticket\nThank you for using our airlines\nWe hope you enjoy your flight");
  240. outfile.close();
  241. } catch (FileNotFoundException e) {
  242. // TODO Auto-generated catch block
  243. e.printStackTrace();
  244.  
  245.  
  246. }
  247. }
  248. }
  249.  
  250. }
  251.  
  252.  
  253. public static void main (String[] args){
  254.  
  255. Lab5 app =new Lab5();
  256. }
  257.  
  258. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement