Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.BorderLayout;
- import java.awt.Dimension;
- import java.awt.FlowLayout;
- import java.awt.event.ActionListener;
- import java.awt.event.ActionEvent;
- import java.awt.event.ItemEvent;
- import java.awt.event.ItemListener;
- import java.awt.event.MouseEvent;
- import java.awt.event.MouseMotionListener;
- import java.awt.GridLayout;
- import javax.swing.JPanel;
- import javax.swing.ImageIcon;
- import javax.swing.JButton;
- import javax.swing.JComboBox;
- import javax.swing.JFrame;
- import javax.swing.JLabel;
- import javax.swing.JOptionPane;
- import javax.swing.JScrollPane;
- import javax.swing.JTable;
- import javax.swing.JTextArea;
- import javax.swing.JTextField;
- import java.util.ArrayList;
- import javax.swing.table.DefaultTableModel;
- import java.io.BufferedReader;
- import java.io.BufferedWriter;
- import java.io.File;
- import java.io.FileInputStream;
- import java.io.FileReader;
- import java.io.FileWriter;
- import java.io.IOException;
- import java.io.InputStreamReader;
- import javax.swing.ImageIcon;
- import java.io.PrintWriter;
- public class AddNewWish {
- public static void main(String[] args) {
- new AddNewWish();
- }
- JTextField from = new JTextField(5);
- JTextField to = new JTextField(5);
- JTextField dateOfDeparture = new JTextField(5);
- JTextField datePliusMinus = new JTextField(5);
- JTextField dateOfReturn = new JTextField(5);
- JTextField datePliusMinus2 = new JTextField(5);
- JTextField numberOfPassengers = new JTextField(5);
- JTextField contactBeforeBooking = new JTextField(5);
- JTextField maxPrice = new JTextField(5);
- JButton btn;
- JButton btn2;
- public AddNewWish(){
- final JFrame frame1 = new JFrame();
- frame1. setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- frame1.setLayout(new BorderLayout());
- frame1.setSize(400, 450);
- frame1.setTitle("Add New Wish");
- frame1.dispose();
- final JPanel north = new JPanel(new GridLayout(10, 2));
- north.add(new JLabel("From where: "));
- north.add(from);
- north.add(new JLabel("To where: "));
- north.add(to);
- north.add(new JLabel("Date of departure"));
- north.add(dateOfDeparture);
- north.add(new JLabel("Date +/-"));
- north.add(datePliusMinus);
- north.add(new JLabel("Date of return"));
- north.add(dateOfReturn);
- north.add(new JLabel("Date +/-"));
- north.add(datePliusMinus2);
- north.add(new JLabel("Number of passengers"));
- north.add(numberOfPassengers);
- north.add(new JLabel("Contact before booking"));
- north.add(contactBeforeBooking);
- north.add(new JLabel("Maximum price"));
- north.add(maxPrice);
- final String[] addOn1 = new String[] {"", "Yes", "No"} ;
- final JComboBox<String> list = new JComboBox<>(addOn1);
- frame1.add(list, BorderLayout.EAST);
- final String[] addOn2 = new String[] {"", "Yes", "No"} ;
- final JComboBox<String> list2 = new JComboBox<>(addOn2);
- frame1.add(list2, BorderLayout.EAST);
- final String[] addOn3 = new String[] {"", "Yes", "No"} ;
- final JComboBox<String> list3 = new JComboBox<>(addOn3);
- frame1.add(list3, BorderLayout.EAST);
- final String[] addOn4 = new String[] {"", "Yes", "No"} ;
- final JComboBox<String> list4 = new JComboBox<>(addOn4);
- frame1.add(list4, BorderLayout.EAST);
- JPanel center = new JPanel(new GridLayout(10, 2));
- frame1.add(center, BorderLayout.CENTER);
- center.add(new JLabel("Do you wish us to rent you a car?"));
- center.add(list);
- center.add(new JLabel("Do you wish us to rent you a hotel?"));
- center.add(list2);
- center.add(new JLabel("Do you wish us to provide transport from/to the airport?"));
- center.add(list3);
- center.add(new JLabel("Do you wish an additional insurance?"));
- center.add(list4);
- frame1.add(north, BorderLayout.NORTH);
- /* final String[] addOn1 = new String[] {"", "Yes", "No"} ;
- final JComboBox<String> list = new JComboBox<>(addOn1);
- frame1.add(list, BorderLayout.EAST); */
- JPanel belekas = new JPanel();
- belekas.add(btn = new JButton("Cancel", new ImageIcon("images\\close.png")));
- btn.setPreferredSize(new Dimension(150, 70));
- btn.addActionListener(
- new ActionListener(){
- public void actionPerformed(ActionEvent arg1)
- {
- frame1.setVisible(false);
- frame1.dispose();
- }});
- belekas.add(btn2 = new JButton("Add Wish", new ImageIcon("images\\ee.png")));
- btn2.setPreferredSize(new Dimension(150,70));
- btn2.addActionListener(
- new ActionListener(){
- public void actionPerformed(ActionEvent arg1){
- if (list.getSelectedItem().toString().isEmpty())
- {
- JOptionPane.showMessageDialog(null, "Please state if you want us to rent a car");
- }
- if (list2.getSelectedItem().toString().isEmpty())
- {
- JOptionPane.showMessageDialog(null, "Please state if you want us to book you a hotel");
- }
- if (list3.getSelectedItem().toString().isEmpty())
- {
- JOptionPane.showMessageDialog(null, "Please state if you want us to provide you with transportation from/to airport");
- }
- if (list4.getSelectedItem().toString().isEmpty())
- {
- JOptionPane.showMessageDialog(null, "Please state if yoo want an insurance");
- }
- try {
- /* FileWriter fw = new FileWriter(new File("bbs.txt"));
- fw.write(from.getText());
- fw.write("\n");
- fw.close(); */
- /* BufferedWriter fileOut = new BufferedWriter(new FileWriter("sudas.txt"));
- fileOut.write(from.getText());
- fileOut.close(); */
- String input = from.getText().trim();
- from.setText(input);
- String input2 = to.getText().trim();
- to.setText(input2);
- String input3 = dateOfDeparture.getText().trim();
- dateOfDeparture.setText(input3);
- String input4 = datePliusMinus.getText().trim();
- datePliusMinus.setText(input4);
- String input5 = dateOfReturn.getText().trim();
- dateOfReturn.setText(input5);
- String input6 = datePliusMinus2.getText().trim();
- datePliusMinus2.setText(input6);
- String input7 = numberOfPassengers.getText().trim();
- numberOfPassengers.setText(input7);
- String input8 = contactBeforeBooking.getText().trim();
- contactBeforeBooking.setText(input8);
- String input9 = maxPrice.getText().trim();
- maxPrice.setText(input9);
- String input10 = list.getSelectedItem().toString();
- list.setSelectedItem(input10);
- String input11 = list2.getSelectedItem().toString();
- list2.setSelectedItem(input11);
- String input12 = list3.getSelectedItem().toString();
- list3.setSelectedItem(input12);
- String input13 = list4.getSelectedItem().toString();
- list4.setSelectedItem(input13);
- PrintWriter writer = new PrintWriter("CustomersWishes.txt");
- writer.print("From where: ");
- writer.print(input);
- writer.println(" ");
- writer.print("To where: ");
- writer.print(input2);
- writer.println(" ");
- writer.print("Date of departure: ");
- writer.print(input3);
- writer.println(" ");
- writer.print("Date +/-: ");
- writer.print(input4);
- writer.println(" ");
- writer.print("Date of return: ");
- writer.print(input5);
- writer.println(" ");
- writer.print("Date +/-: ");
- writer.print(input6);
- writer.println(" ");
- writer.print("Number of passengers: ");
- writer.print(input7);
- writer.println(" ");
- writer.print("Contact before booking: ");
- writer.print(input8);
- writer.println(" ");
- writer.print("Maximum price: ");
- writer.print(input9);
- writer.println(" ");
- writer.print("Wish to rent a car: ");
- writer.print(input10);
- writer.println(" ");
- writer.print("Wish to rent a hotel: ");
- writer.print(input11);
- writer.println(" ");
- writer.print("Wish to get transportation from/to the airport: ");
- writer.print(input12);
- writer.println(" ");
- writer.print("Wish to get an additional insurance: ");
- writer.print(input13);
- frame1.setVisible(false);
- writer.close();
- frame1.dispose();
- }
- catch(Exception ex){
- ex.printStackTrace();
- }
- from.addActionListener(this);
- }});
- frame1.add(belekas, BorderLayout.SOUTH);
- frame1.setVisible(true);
- frame1.pack();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement