Advertisement
Guest User

Untitled

a guest
May 24th, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.78 KB | None | 0 0
  1. public class PurchaseGUI extends JFrame
  2. {
  3.     File offersFile = new File ("Offers.txt");
  4.     private List<Purchase> offers = new ArrayList<>();
  5.     private PropertyGUI propGUI = new PropertyGUI();
  6.     private Sale sale = new Sale();
  7.     public PurchaseGUI()
  8.     {
  9.         JPanel selectProp = new JPanel();
  10.         JLabel propSelect = new JLabel("Enter a property address: ");
  11.         selectProp.add(propSelect);
  12.         JTextField enterProp = new JTextField(30);
  13.         selectProp.add(enterProp);
  14.  
  15.         JPanel addOffer = new JPanel();
  16.         JLabel offerAmt = new JLabel("Enter offer amount: ");
  17.         addOffer.add(offerAmt);
  18.         JTextField enterOffer = new JTextField(20);
  19.         addOffer.add(enterOffer);
  20.  
  21.         JPanel offerDate = new JPanel();
  22.         JLabel offer_Date = new JLabel("Enter date of purchase offer: ");
  23.         offerDate.add(offer_Date);
  24.         JTextField enterPurchDate = new JTextField(10);
  25.         offerDate.add(enterPurchDate);
  26.  
  27.         JPanel buyerName = new JPanel();
  28.         JLabel nameOfBuyer = new JLabel("Enter name of buyer: ");
  29.         buyerName.add(nameOfBuyer);
  30.         JTextField enterBuyerName = new JTextField(30);
  31.         buyerName.add(enterBuyerName);
  32.  
  33.  
  34.         JPanel buyerPhone = new JPanel();
  35.         JLabel phoneNum = new JLabel("Enter phone number of buyer: ");
  36.         buyerPhone.add(phoneNum);
  37.         JTextField enterBuyerPhone = new JTextField(15);
  38.         buyerPhone.add(enterBuyerPhone);
  39.  
  40.         JPanel bttnPanel = new JPanel();
  41.         JButton addBttn = new JButton("Add offer");
  42.         bttnPanel.add(addBttn);
  43.         JButton clearBttn = new JButton("Clear");
  44.         bttnPanel.add(clearBttn);
  45.         JButton cancelBttn = new JButton("Cancel");
  46.         bttnPanel.add(cancelBttn);
  47.  
  48.  
  49.  
  50.         List<Sale> saleList = propGUI.getSaleList();
  51.  
  52.         setLayout(new GridBagLayout());//Setting the frame layout to GridBagLayout
  53.         GridBagConstraints gbc = new GridBagConstraints();
  54.         gbc.weightx = 1;
  55.         gbc.weighty = 1;
  56.  
  57.  
  58.  
  59.  
  60.         gbc.gridx = 0;
  61.         gbc.gridy = 1;
  62.         gbc.gridheight = 1;
  63.         gbc.anchor = GridBagConstraints.WEST;
  64.         add(selectProp, gbc);//Adding the welcomeLabel to the frame*/
  65.  
  66.         gbc.gridx = 0;
  67.         gbc.gridy = 2;
  68.         gbc.gridheight = 1;
  69.         gbc.anchor = GridBagConstraints.WEST;
  70.         add(addOffer, gbc);//Adding the welcomeLabel to the frame*/
  71.  
  72.         gbc.gridx = 0;
  73.         gbc.gridy = 3;
  74.         gbc.gridheight = 1;
  75.         gbc.anchor = GridBagConstraints.WEST;
  76.         add(offerDate, gbc);//Adding the welcomeLabel to the frame*/
  77.  
  78.         gbc.gridx = 0;
  79.         gbc.gridy = 4;
  80.         gbc.gridheight = 1;
  81.         gbc.anchor = GridBagConstraints.WEST;
  82.         add(buyerName, gbc);//Adding the welcomeLabel to the frame*/
  83.  
  84.         gbc.gridx = 0;
  85.         gbc.gridy = 5;
  86.         gbc.gridheight = 1;
  87.         gbc.anchor = GridBagConstraints.WEST;
  88.         add(buyerPhone, gbc);//Adding the welcomeLabel to the frame*/
  89.  
  90.  
  91.         gbc.gridx = 0;
  92.         gbc.gridy = 6;
  93.         gbc.gridheight = 1;
  94.         gbc.anchor = GridBagConstraints.EAST;
  95.         add(bttnPanel, gbc);//Adding the sellerPanel to the frame
  96.  
  97.  
  98.  
  99.         cancelBttn.addActionListener(new ActionListener()//Adding an ActionListener to the exitButton
  100.         {
  101.             public void actionPerformed(ActionEvent e)
  102.             {
  103.                 int response = JOptionPane.showConfirmDialog(null, "Are you sure you want to exit the purchase window?", "CQ Real Estate App", JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE);
  104.                 if (response == JOptionPane.OK_OPTION)//Message asking the user if they are sure they wish to exit the application
  105.                 {
  106.                         JFrame closePurchGUI = new PurchaseGUI();
  107.                         dispose();
  108.  
  109.                 }
  110.             }
  111.         });
  112.  
  113.  
  114.         addBttn.addActionListener(new ActionListener()
  115.         {
  116.             public void actionPerformed(ActionEvent e)
  117.             {
  118.                 /*for(int i = 0; i < saleList.size();i++)
  119.                 {
  120.                     if(props.equals(saleList.get(i).getPropertyAddress()))
  121.                     {
  122.                     }
  123.                     else
  124.                     {
  125.                         JOptionPane.showMessageDialog(null, "No such property");
  126.                     }
  127.                 }
  128.  
  129.                 for(Sale var: saleList)
  130.                 {
  131.  
  132.                     System.out.println(var);
  133.  
  134.                 }*/
  135.  
  136.                 try (BufferedReader br = new BufferedReader(new FileReader("SalesFile.txt")))
  137.                 {
  138.                     String line;
  139.                     while ((line = br.readLine()) != null)
  140.                     {
  141.  
  142.                        if(line.toLowerCase().contains(enterProp.getText().toLowerCase()))
  143.                        {
  144.                            Purchase offerList = new Purchase();
  145.                            offerList.setPropAddress(enterProp.getText());
  146.                            offerList.setAmountOffered(Double.parseDouble(enterOffer.getText().toString()));
  147.                            offerList.setPurchOfferDate(enterPurchDate.getText());
  148.                            offerList.setNameOfBuyer(enterBuyerName.getText());
  149.                            offerList.setBuyerPhone(enterBuyerPhone.getText());;
  150.                            offers.add(offerList);
  151.  
  152.  
  153.                        }
  154.                        else if(!line.toLowerCase().contains(enterProp.getText().toLowerCase()));
  155.                        {
  156.                            JOptionPane.showMessageDialog(null, "Cannot find property");
  157.                        }
  158.                     }
  159.                 }
  160.  
  161.                 catch (IOException ee)
  162.                 {
  163.  
  164.                     return;
  165.                 }
  166.  
  167.                 try
  168.                 {
  169.                     FileWriter fw = new FileWriter (offersFile, true);
  170.                     BufferedWriter output = new BufferedWriter(fw);
  171.                     int size = offers.size();
  172.                     for (int i = 0; i < size; i++)
  173.                     {
  174.                         output.write(offers.get(i).toString());
  175.                         output.newLine();
  176.                     }
  177.                     output.close();
  178.                 }
  179.  
  180.                 catch (IOException ex)
  181.                 {
  182.                     JOptionPane.showMessageDialog(null, "File not found.");
  183.                 }
  184.             }
  185.         });
  186.  
  187.         /*props.addActionListener(new ActionListener()
  188.         {
  189.             public void actionPerformed(ActionEvent e)
  190.             {
  191.                 for(int i = 0; i < saleList.size();i++)
  192.                 {
  193.                     if(props.equals(saleList.get(i).getPropertyAddress()))
  194.                     {
  195.                     }
  196.                     else
  197.                     {
  198.                         JOptionPane.showMessageDialog(null, "No such property");
  199.                     }
  200.                 }
  201.             }
  202.         });*/
  203.     }
  204.  
  205.  
  206.     public static void main(String[] args)//main method
  207.                 {
  208.                     EventQueue.invokeLater(() ->
  209.                     {
  210.                         JFrame frame = new PurchaseGUI();
  211.                         frame.setTitle("CQ Real Estate");
  212.                         frame.setSize(500, 400);
  213.                         frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  214.                         frame.setVisible(true);
  215.                         frame.pack();
  216.  
  217.  
  218.                     });
  219.             }
  220.  
  221. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement