Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class PurchaseGUI extends JFrame
- {
- File offersFile = new File ("Offers.txt");
- private List<Purchase> offers = new ArrayList<>();
- private PropertyGUI propGUI = new PropertyGUI();
- private Sale sale = new Sale();
- public PurchaseGUI()
- {
- JPanel selectProp = new JPanel();
- JLabel propSelect = new JLabel("Enter a property address: ");
- selectProp.add(propSelect);
- JTextField enterProp = new JTextField(30);
- selectProp.add(enterProp);
- JPanel addOffer = new JPanel();
- JLabel offerAmt = new JLabel("Enter offer amount: ");
- addOffer.add(offerAmt);
- JTextField enterOffer = new JTextField(20);
- addOffer.add(enterOffer);
- JPanel offerDate = new JPanel();
- JLabel offer_Date = new JLabel("Enter date of purchase offer: ");
- offerDate.add(offer_Date);
- JTextField enterPurchDate = new JTextField(10);
- offerDate.add(enterPurchDate);
- JPanel buyerName = new JPanel();
- JLabel nameOfBuyer = new JLabel("Enter name of buyer: ");
- buyerName.add(nameOfBuyer);
- JTextField enterBuyerName = new JTextField(30);
- buyerName.add(enterBuyerName);
- JPanel buyerPhone = new JPanel();
- JLabel phoneNum = new JLabel("Enter phone number of buyer: ");
- buyerPhone.add(phoneNum);
- JTextField enterBuyerPhone = new JTextField(15);
- buyerPhone.add(enterBuyerPhone);
- JPanel bttnPanel = new JPanel();
- JButton addBttn = new JButton("Add offer");
- bttnPanel.add(addBttn);
- JButton clearBttn = new JButton("Clear");
- bttnPanel.add(clearBttn);
- JButton cancelBttn = new JButton("Cancel");
- bttnPanel.add(cancelBttn);
- List<Sale> saleList = propGUI.getSaleList();
- setLayout(new GridBagLayout());//Setting the frame layout to GridBagLayout
- GridBagConstraints gbc = new GridBagConstraints();
- gbc.weightx = 1;
- gbc.weighty = 1;
- gbc.gridx = 0;
- gbc.gridy = 1;
- gbc.gridheight = 1;
- gbc.anchor = GridBagConstraints.WEST;
- add(selectProp, gbc);//Adding the welcomeLabel to the frame*/
- gbc.gridx = 0;
- gbc.gridy = 2;
- gbc.gridheight = 1;
- gbc.anchor = GridBagConstraints.WEST;
- add(addOffer, gbc);//Adding the welcomeLabel to the frame*/
- gbc.gridx = 0;
- gbc.gridy = 3;
- gbc.gridheight = 1;
- gbc.anchor = GridBagConstraints.WEST;
- add(offerDate, gbc);//Adding the welcomeLabel to the frame*/
- gbc.gridx = 0;
- gbc.gridy = 4;
- gbc.gridheight = 1;
- gbc.anchor = GridBagConstraints.WEST;
- add(buyerName, gbc);//Adding the welcomeLabel to the frame*/
- gbc.gridx = 0;
- gbc.gridy = 5;
- gbc.gridheight = 1;
- gbc.anchor = GridBagConstraints.WEST;
- add(buyerPhone, gbc);//Adding the welcomeLabel to the frame*/
- gbc.gridx = 0;
- gbc.gridy = 6;
- gbc.gridheight = 1;
- gbc.anchor = GridBagConstraints.EAST;
- add(bttnPanel, gbc);//Adding the sellerPanel to the frame
- cancelBttn.addActionListener(new ActionListener()//Adding an ActionListener to the exitButton
- {
- public void actionPerformed(ActionEvent e)
- {
- 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);
- if (response == JOptionPane.OK_OPTION)//Message asking the user if they are sure they wish to exit the application
- {
- JFrame closePurchGUI = new PurchaseGUI();
- dispose();
- }
- }
- });
- addBttn.addActionListener(new ActionListener()
- {
- public void actionPerformed(ActionEvent e)
- {
- /*for(int i = 0; i < saleList.size();i++)
- {
- if(props.equals(saleList.get(i).getPropertyAddress()))
- {
- }
- else
- {
- JOptionPane.showMessageDialog(null, "No such property");
- }
- }
- for(Sale var: saleList)
- {
- System.out.println(var);
- }*/
- try (BufferedReader br = new BufferedReader(new FileReader("SalesFile.txt")))
- {
- String line;
- while ((line = br.readLine()) != null)
- {
- if(line.toLowerCase().contains(enterProp.getText().toLowerCase()))
- {
- Purchase offerList = new Purchase();
- offerList.setPropAddress(enterProp.getText());
- offerList.setAmountOffered(Double.parseDouble(enterOffer.getText().toString()));
- offerList.setPurchOfferDate(enterPurchDate.getText());
- offerList.setNameOfBuyer(enterBuyerName.getText());
- offerList.setBuyerPhone(enterBuyerPhone.getText());;
- offers.add(offerList);
- }
- else if(!line.toLowerCase().contains(enterProp.getText().toLowerCase()));
- {
- JOptionPane.showMessageDialog(null, "Cannot find property");
- }
- }
- }
- catch (IOException ee)
- {
- return;
- }
- try
- {
- FileWriter fw = new FileWriter (offersFile, true);
- BufferedWriter output = new BufferedWriter(fw);
- int size = offers.size();
- for (int i = 0; i < size; i++)
- {
- output.write(offers.get(i).toString());
- output.newLine();
- }
- output.close();
- }
- catch (IOException ex)
- {
- JOptionPane.showMessageDialog(null, "File not found.");
- }
- }
- });
- /*props.addActionListener(new ActionListener()
- {
- public void actionPerformed(ActionEvent e)
- {
- for(int i = 0; i < saleList.size();i++)
- {
- if(props.equals(saleList.get(i).getPropertyAddress()))
- {
- }
- else
- {
- JOptionPane.showMessageDialog(null, "No such property");
- }
- }
- }
- });*/
- }
- public static void main(String[] args)//main method
- {
- EventQueue.invokeLater(() ->
- {
- JFrame frame = new PurchaseGUI();
- frame.setTitle("CQ Real Estate");
- frame.setSize(500, 400);
- frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- frame.setVisible(true);
- frame.pack();
- });
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement