diff --git a/MerchantRPGCSE2102/src/model/Map.java b/MerchantRPGCSE2102/src/model/Map.java index 6ffaf97..bff4432 100644 --- a/MerchantRPGCSE2102/src/model/Map.java +++ b/MerchantRPGCSE2102/src/model/Map.java @@ -16,7 +16,7 @@ public Map(int rows, int cols) { } /** - * This method stores the sepcified instance of Player at the specified position on the map + * This method stores the specified instance of Player at the specified position on the map * @param player The player to be initialized * @param row The row of the player's location * @param column The column of the player's location @@ -89,6 +89,7 @@ public void movePlayer(String direction) { } } } + } /** diff --git a/MerchantRPGCSE2102/src/view/StartScreen.java b/MerchantRPGCSE2102/src/view/StartScreen.java index d7e8e4a..4d900dd 100644 --- a/MerchantRPGCSE2102/src/view/StartScreen.java +++ b/MerchantRPGCSE2102/src/view/StartScreen.java @@ -53,8 +53,8 @@ public void actionPerformed(ActionEvent e){ start.setBackground(null); instructions.setBackground(null); this.add(panel); - this.add(instructions); - this.add(start); + this.getContentPane().add(instructions); + this.getContentPane().add(start); } public BufferedImage loadIcon() throws IOException { diff --git a/MerchantRPGCSE2102/src/view/TransactionUI.java b/MerchantRPGCSE2102/src/view/TransactionUI.java index 2e5ef56..033be48 100644 --- a/MerchantRPGCSE2102/src/view/TransactionUI.java +++ b/MerchantRPGCSE2102/src/view/TransactionUI.java @@ -17,16 +17,14 @@ @SuppressWarnings("serial") public class TransactionUI extends JFrame { - private JPanel transactionPanel; + private static JPanel transactionPanel; 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 - + /** * Create the frame. */ public TransactionUI(Transaction master) { MASTER = master; - _inTransaction = false; setTitle("Transaction Window"); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setBounds(100, 100, 600, 430); @@ -41,22 +39,20 @@ public void actionPerformed(ActionEvent arg0) { }); btnBuy.addMouseListener(new MouseAdapter() { @Override - public void mouseClicked(MouseEvent arg0) { + public void mouseReleased(MouseEvent arg0) { System.out.println("BUY"); //temporary test code - if(!_inTransaction) //checks if there is another transaction window open if not, then creates a buy transaction window - createBuyWindow(); - } - }); + createBuyWindow(); + } + }); btnBuy.setBounds(58, 155, 169, 105); transactionPanel.add(btnBuy); JButton btnSell = new JButton("SELL"); //creates a "Sell" button btnSell.addMouseListener(new MouseAdapter() { @Override - public void mouseClicked(MouseEvent e) { + public void mouseReleased(MouseEvent e) { System.out.println("SELL"); //temporary test code - if(!_inTransaction) //checks if there is another transaction window open, if not creates a sell transaction window - createSellWindow(); + createSellWindow(); } }); btnSell.setBounds(351, 155, 169, 105); @@ -65,13 +61,11 @@ public void mouseClicked(MouseEvent e) { JButton btnCancel = new JButton("End Transaction"); //creates a button to end the transaction btnCancel.addMouseListener(new MouseAdapter() { @Override - public void mouseClicked(MouseEvent e) { + public void mouseReleased(MouseEvent e) { System.out.println("Cancel"); //temporary test code - if(!_inTransaction) - { + MASTER.actionCancel(); exitWindow(); //Will end the transaction main screen but only if player does not have another transaction screen open - } } }); btnCancel.setBounds(210, 310, 160, 50); @@ -105,7 +99,6 @@ public void exitWindow() */ public void createBuyWindow() { - _inTransaction = true; //does not allow new transaction windows to be opened while buy window is JPanel contentPane = new JPanel(); contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); contentPane.setLayout(null); @@ -147,8 +140,7 @@ public void createBuyWindow() JButton btnCancel = new JButton("Cancel"); //cancel button, re-enables the player's ability to call new transaction windows btnCancel.addMouseListener(new MouseAdapter() { @Override - public void mouseClicked(MouseEvent arg0) { - _inTransaction = false; + public void mouseReleased(MouseEvent arg0) { getContentPane().removeAll(); add(transactionPanel); setVisible(false); @@ -161,7 +153,7 @@ public void mouseClicked(MouseEvent arg0) { JButton btnAccept = new JButton("Accept"); //create an accept button to consume the information the player entered into the menu and text field btnAccept.addMouseListener(new MouseAdapter() { @Override - public void mouseClicked(MouseEvent e) { //information is consumed when player clicks the accept button + public void mouseReleased(MouseEvent e) { //information is consumed when player clicks the accept button String chosenItem = comboBox.getSelectedItem().toString().split(" ")[0]; //consumes the String name of the item from drop-down menu System.out.println(chosenItem); @@ -170,18 +162,17 @@ public void mouseClicked(MouseEvent e) { //information is consumed whe if(MASTER.actionBuy(chosenItem, chosenAmount)) //will attempt to buy the specified amount of the chosen item { System.out.println(chosenAmount); - _inTransaction = false; getContentPane().removeAll(); add(transactionPanel); setVisible(false); setVisible(true); - dispose(); } else throw new NumberFormatException(); //will throw a NumberFormatException if actionBuy returns a false } catch(NumberFormatException exception){ System.out.println("Must input an amount that you can afford"); + createWarning("Must input an amount that you can afford"); } } }); @@ -196,7 +187,6 @@ public void mouseClicked(MouseEvent e) { //information is consumed whe @SuppressWarnings({ "unchecked", "rawtypes" }) public void createSellWindow() { - _inTransaction = true; //does not allow new transaction windows to be opened if sell window is JPanel contentPane = new JPanel(); contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); contentPane.setLayout(null); @@ -237,8 +227,7 @@ public void createSellWindow() JButton btnCancel = new JButton("Cancel"); //cancel button, re-enables the player's ability to call new transaction windows btnCancel.addMouseListener(new MouseAdapter() { @Override - public void mouseClicked(MouseEvent arg0) { - _inTransaction = false; + public void mouseReleased(MouseEvent arg0) { getContentPane().removeAll(); add(transactionPanel); setVisible(false); @@ -251,7 +240,7 @@ public void mouseClicked(MouseEvent arg0) { JButton btnAccept = new JButton("Accept"); //create an accept button to consume the information the player entered into the menu and text field btnAccept.addMouseListener(new MouseAdapter() { @Override - public void mouseClicked(MouseEvent e) { //information is consumed when player clicks the accept button + public void mouseReleased(MouseEvent e) { //information is consumed when player clicks the accept button String chosenItem = comboBox.getSelectedItem().toString().split(" ")[0]; //consumes the String name of the item from drop-down menu System.out.println(chosenItem); boolean isGood = false; @@ -264,26 +253,27 @@ public void mouseClicked(MouseEvent e) { //information is consumed w if(isGood) //will attempt to sell the specified amount of the chosen item { System.out.println(chosenAmount); - _inTransaction = false; getContentPane().removeAll(); add(transactionPanel); setVisible(false); setVisible(true); - dispose(); } else throw new NumberFormatException(); //will throw a NumberFormatException if actionSell returns a false } 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"); } } }); @@ -292,4 +282,30 @@ public void mouseClicked(MouseEvent e) { //information is consumed w // frame.setVisible(true); // frame.setLocationRelativeTo(null); } + + public static void createWarning(String message) { + final JFrame contentFrame = new JFrame(); + JPanel warningPane = new JPanel(); + contentFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); + contentFrame.setBounds(100, 100, 450, 300); + warningPane = new JPanel(); + warningPane.setBorder(new EmptyBorder(5, 5, 5, 5)); + contentFrame.setContentPane(warningPane); + warningPane.setLayout(null); + + JButton btnOk = new JButton("Ok"); + btnOk.addMouseListener(new MouseAdapter() { + @Override + public void mouseReleased(MouseEvent arg0) { + contentFrame.dispose(); + } + }); + btnOk.setBounds(162, 203, 103, 32); + warningPane.add(btnOk); + + JLabel lblNewLabel = new JLabel(message); + lblNewLabel.setBounds(80, 102, 265, 49); + warningPane.add(lblNewLabel); + contentFrame.setVisible(true); + } }