Advertisement
Guest User

Untitled

a guest
May 22nd, 2015
216
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.20 KB | None | 0 0
  1. import java.awt.BorderLayout;
  2. import java.awt.Dimension;
  3. import java.awt.FlowLayout;
  4. import java.awt.event.ActionListener;
  5. import java.awt.event.ActionEvent;
  6. import java.awt.event.ItemEvent;
  7. import java.awt.event.ItemListener;
  8. import java.awt.event.MouseEvent;
  9. import java.awt.event.MouseMotionListener;
  10. import java.awt.GridLayout;
  11.  
  12.  
  13. import javax.swing.JPanel;
  14. import javax.swing.ImageIcon;
  15. import javax.swing.JButton;
  16. import javax.swing.JComboBox;
  17. import javax.swing.JFrame;
  18. import javax.swing.JLabel;
  19. import javax.swing.JOptionPane;
  20. import javax.swing.JScrollPane;
  21. import javax.swing.JTable;
  22. import javax.swing.JTextArea;
  23. import javax.swing.JTextField;
  24. import java.util.ArrayList;
  25. import javax.swing.table.DefaultTableModel;
  26.  
  27. import java.io.BufferedReader;
  28. import java.io.BufferedWriter;
  29. import java.io.File;
  30. import java.io.FileInputStream;
  31. import java.io.FileReader;
  32. import java.io.FileWriter;
  33. import java.io.IOException;
  34. import java.io.InputStreamReader;
  35. import javax.swing.ImageIcon;
  36. import java.io.PrintWriter;
  37.  
  38.  
  39. public class AddNewWish {
  40. public static void main(String[] args) {
  41. new AddNewWish();
  42. }
  43. JTextField from = new JTextField(5);
  44. JTextField to = new JTextField(5);
  45. JTextField dateOfDeparture = new JTextField(5);
  46. JTextField datePliusMinus = new JTextField(5);
  47. JTextField dateOfReturn = new JTextField(5);
  48. JTextField datePliusMinus2 = new JTextField(5);
  49. JTextField numberOfPassengers = new JTextField(5);
  50. JTextField contactBeforeBooking = new JTextField(5);
  51. JTextField maxPrice = new JTextField(5);
  52. JButton btn;
  53. JButton btn2;
  54.  
  55.  
  56.  
  57. public AddNewWish(){
  58.  
  59.  
  60.  
  61.  
  62.  
  63.  
  64. final JFrame frame1 = new JFrame();
  65. frame1. setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  66. frame1.setLayout(new BorderLayout());
  67. frame1.setSize(400, 450);
  68. frame1.setTitle("Add New Wish");
  69. frame1.dispose();
  70.  
  71.  
  72. final JPanel north = new JPanel(new GridLayout(10, 2));
  73. north.add(new JLabel("From where: "));
  74. north.add(from);
  75. north.add(new JLabel("To where: "));
  76. north.add(to);
  77. north.add(new JLabel("Date of departure"));
  78. north.add(dateOfDeparture);
  79. north.add(new JLabel("Date +/-"));
  80. north.add(datePliusMinus);
  81. north.add(new JLabel("Date of return"));
  82. north.add(dateOfReturn);
  83. north.add(new JLabel("Date +/-"));
  84. north.add(datePliusMinus2);
  85. north.add(new JLabel("Number of passengers"));
  86. north.add(numberOfPassengers);
  87. north.add(new JLabel("Contact before booking"));
  88. north.add(contactBeforeBooking);
  89. north.add(new JLabel("Maximum price"));
  90. north.add(maxPrice);
  91.  
  92.  
  93.  
  94.  
  95. final String[] addOn1 = new String[] {"", "Yes", "No"} ;
  96. final JComboBox<String> list = new JComboBox<>(addOn1);
  97. frame1.add(list, BorderLayout.EAST);
  98.  
  99. final String[] addOn2 = new String[] {"", "Yes", "No"} ;
  100. final JComboBox<String> list2 = new JComboBox<>(addOn2);
  101. frame1.add(list2, BorderLayout.EAST);
  102.  
  103. final String[] addOn3 = new String[] {"", "Yes", "No"} ;
  104. final JComboBox<String> list3 = new JComboBox<>(addOn3);
  105. frame1.add(list3, BorderLayout.EAST);
  106.  
  107. final String[] addOn4 = new String[] {"", "Yes", "No"} ;
  108. final JComboBox<String> list4 = new JComboBox<>(addOn4);
  109. frame1.add(list4, BorderLayout.EAST);
  110.  
  111.  
  112. JPanel center = new JPanel(new GridLayout(10, 2));
  113. frame1.add(center, BorderLayout.CENTER);
  114.  
  115. center.add(new JLabel("Do you wish us to rent you a car?"));
  116. center.add(list);
  117. center.add(new JLabel("Do you wish us to rent you a hotel?"));
  118. center.add(list2);
  119. center.add(new JLabel("Do you wish us to provide transport from/to the airport?"));
  120. center.add(list3);
  121. center.add(new JLabel("Do you wish an additional insurance?"));
  122. center.add(list4);
  123.  
  124.  
  125.  
  126.  
  127.  
  128.  
  129.  
  130. frame1.add(north, BorderLayout.NORTH);
  131.  
  132. /* final String[] addOn1 = new String[] {"", "Yes", "No"} ;
  133. final JComboBox<String> list = new JComboBox<>(addOn1);
  134. frame1.add(list, BorderLayout.EAST); */
  135.  
  136.  
  137.  
  138.  
  139.  
  140. JPanel belekas = new JPanel();
  141. belekas.add(btn = new JButton("Cancel", new ImageIcon("images\\close.png")));
  142. btn.setPreferredSize(new Dimension(150, 70));
  143. btn.addActionListener(
  144. new ActionListener(){
  145. public void actionPerformed(ActionEvent arg1)
  146. {
  147.  
  148.  
  149. frame1.setVisible(false);
  150. frame1.dispose();
  151.  
  152. }});
  153.  
  154.  
  155.  
  156.  
  157. belekas.add(btn2 = new JButton("Add Wish", new ImageIcon("images\\ee.png")));
  158. btn2.setPreferredSize(new Dimension(150,70));
  159. btn2.addActionListener(
  160. new ActionListener(){
  161. public void actionPerformed(ActionEvent arg1){
  162.  
  163. if (list.getSelectedItem().toString().isEmpty())
  164. {
  165.  
  166. JOptionPane.showMessageDialog(null, "Please state if you want us to rent a car");
  167.  
  168. }
  169. if (list2.getSelectedItem().toString().isEmpty())
  170. {
  171.  
  172. JOptionPane.showMessageDialog(null, "Please state if you want us to book you a hotel");
  173.  
  174. }
  175. if (list3.getSelectedItem().toString().isEmpty())
  176. {
  177.  
  178. JOptionPane.showMessageDialog(null, "Please state if you want us to provide you with transportation from/to airport");
  179.  
  180. }
  181.  
  182. if (list4.getSelectedItem().toString().isEmpty())
  183. {
  184.  
  185. JOptionPane.showMessageDialog(null, "Please state if yoo want an insurance");
  186.  
  187. }
  188.  
  189.  
  190.  
  191. try {
  192.  
  193.  
  194. /* FileWriter fw = new FileWriter(new File("bbs.txt"));
  195. fw.write(from.getText());
  196. fw.write("\n");
  197. fw.close(); */
  198.  
  199. /* BufferedWriter fileOut = new BufferedWriter(new FileWriter("sudas.txt"));
  200. fileOut.write(from.getText());
  201. fileOut.close(); */
  202.  
  203.  
  204.  
  205.  
  206. String input = from.getText().trim();
  207. from.setText(input);
  208.  
  209. String input2 = to.getText().trim();
  210. to.setText(input2);
  211.  
  212. String input3 = dateOfDeparture.getText().trim();
  213. dateOfDeparture.setText(input3);
  214.  
  215. String input4 = datePliusMinus.getText().trim();
  216. datePliusMinus.setText(input4);
  217.  
  218. String input5 = dateOfReturn.getText().trim();
  219. dateOfReturn.setText(input5);
  220.  
  221. String input6 = datePliusMinus2.getText().trim();
  222. datePliusMinus2.setText(input6);
  223.  
  224. String input7 = numberOfPassengers.getText().trim();
  225. numberOfPassengers.setText(input7);
  226.  
  227. String input8 = contactBeforeBooking.getText().trim();
  228. contactBeforeBooking.setText(input8);
  229.  
  230. String input9 = maxPrice.getText().trim();
  231. maxPrice.setText(input9);
  232.  
  233. String input10 = list.getSelectedItem().toString();
  234. list.setSelectedItem(input10);
  235.  
  236. String input11 = list2.getSelectedItem().toString();
  237. list2.setSelectedItem(input11);
  238.  
  239. String input12 = list3.getSelectedItem().toString();
  240. list3.setSelectedItem(input12);
  241.  
  242. String input13 = list4.getSelectedItem().toString();
  243. list4.setSelectedItem(input13);
  244.  
  245.  
  246. PrintWriter writer = new PrintWriter("CustomersWishes.txt");
  247. writer.print("From where: ");
  248. writer.print(input);
  249. writer.println(" ");
  250. writer.print("To where: ");
  251. writer.print(input2);
  252. writer.println(" ");
  253. writer.print("Date of departure: ");
  254. writer.print(input3);
  255. writer.println(" ");
  256. writer.print("Date +/-: ");
  257. writer.print(input4);
  258. writer.println(" ");
  259. writer.print("Date of return: ");
  260. writer.print(input5);
  261. writer.println(" ");
  262. writer.print("Date +/-: ");
  263. writer.print(input6);
  264. writer.println(" ");
  265. writer.print("Number of passengers: ");
  266. writer.print(input7);
  267. writer.println(" ");
  268. writer.print("Contact before booking: ");
  269. writer.print(input8);
  270. writer.println(" ");
  271. writer.print("Maximum price: ");
  272. writer.print(input9);
  273. writer.println(" ");
  274. writer.print("Wish to rent a car: ");
  275. writer.print(input10);
  276. writer.println(" ");
  277. writer.print("Wish to rent a hotel: ");
  278. writer.print(input11);
  279. writer.println(" ");
  280. writer.print("Wish to get transportation from/to the airport: ");
  281. writer.print(input12);
  282. writer.println(" ");
  283. writer.print("Wish to get an additional insurance: ");
  284. writer.print(input13);
  285.  
  286.  
  287. frame1.setVisible(false);
  288.  
  289. writer.close();
  290. frame1.dispose();
  291.  
  292. }
  293. catch(Exception ex){
  294. ex.printStackTrace();
  295. }
  296.  
  297. from.addActionListener(this);
  298.  
  299.  
  300. }});
  301.  
  302.  
  303.  
  304.  
  305. frame1.add(belekas, BorderLayout.SOUTH);
  306.  
  307.  
  308. frame1.setVisible(true);
  309. frame1.pack();
  310.  
  311.  
  312. }
  313.  
  314. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement