From afd2d9e7818d55bfd86f4d5833743270834e5509 Mon Sep 17 00:00:00 2001 From: Gavin Li Date: Sun, 29 Mar 2015 20:24:47 -0400 Subject: [PATCH] Warning messages are now displayed in windows --- .../src/view/TransactionUI.java | 37 +++++++++++++++++-- 1 file changed, 34 insertions(+), 3 deletions(-) diff --git a/MerchantRPGCSE2102/src/view/TransactionUI.java b/MerchantRPGCSE2102/src/view/TransactionUI.java index bd72d3e..48181fb 100644 --- a/MerchantRPGCSE2102/src/view/TransactionUI.java +++ b/MerchantRPGCSE2102/src/view/TransactionUI.java @@ -1,6 +1,7 @@ package view; import java.awt.EventQueue; +import java.awt.FlowLayout; import javax.swing.JComboBox; import javax.swing.JFrame; @@ -26,7 +27,7 @@ @SuppressWarnings("serial") public class TransactionUI extends JFrame { - private JPanel contentPane; + private static JPanel contentPane; private static Transaction MASTER; //TransactionUI class will hold the instance of the Transaction that created it private static boolean _inTransaction; //Prevents the user from making multiple transaction windows @@ -201,6 +202,7 @@ public void mouseClicked(MouseEvent e) { //information is consumed whe } catch(NumberFormatException exception){ System.out.println("Must input an amount that you can afford"); + createWarning("Must input an amount that you can afford"); } } }); @@ -292,14 +294,17 @@ public void mouseClicked(MouseEvent e) { //information is consumed w } catch(MerchantNotEnoughCashException mnecexception){ System.out.println("Merchant does not have enough cash"); + createWarning("Merchant does not have enough cash"); } } catch(NumberFormatException exception){ - System.out.println("Must input a number less than or equal to the total amount of the item that you have"); + System.out.println("You do not have enough of that item"); + createWarning("You do not have enough of that item"); } } catch(NotInInventoryException niiexception){ - System.out.println("Merchant does not accept that item");; + System.out.println("Merchant does not accept that item"); + createWarning("Merchant does not accept that item"); } } }); @@ -307,4 +312,30 @@ public void mouseClicked(MouseEvent e) { //information is consumed w contentPane.add(btnAccept); frame.setVisible(true); } + + public static void createWarning(String message) { + final JFrame contentFrame = new JFrame(); + contentFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); + contentFrame.setBounds(100, 100, 450, 300); + contentPane = new JPanel(); + contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); + contentFrame.setContentPane(contentPane); + contentPane.setLayout(null); + + JButton btnOk = new JButton("Ok"); + btnOk.addMouseListener(new MouseAdapter() { + @Override + public void mouseClicked(MouseEvent arg0) { + _inTransaction = false; + contentFrame.dispose(); + } + }); + btnOk.setBounds(162, 203, 103, 32); + contentPane.add(btnOk); + + JLabel lblNewLabel = new JLabel(message); + lblNewLabel.setBounds(80, 102, 265, 49); + contentPane.add(lblNewLabel); + contentFrame.setVisible(true); + } }