diff --git a/MerchantRPGCSE2102/src/controller/RPGame.java b/MerchantRPGCSE2102/src/controller/RPGame.java index 686f23e..53f67df 100644 --- a/MerchantRPGCSE2102/src/controller/RPGame.java +++ b/MerchantRPGCSE2102/src/controller/RPGame.java @@ -175,6 +175,7 @@ public static void main(String[] args) playerInventory.addAll(_rpg.getMerchantInventoryList(2)); playerInventory.addAll(_rpg.getMerchantInventoryList(3)); _rpg.buildPlayer("test", 500, playerInventory); + _rpg.getPlayer().getItem("armor").increaseQuantity(15); _rpg.createTransaction(_rpg.getPlayer(), _rpg.getMerchant(1)); } } diff --git a/MerchantRPGCSE2102/src/view/Test.java b/MerchantRPGCSE2102/src/view/Test.java index 25ea64b..072e852 100644 --- a/MerchantRPGCSE2102/src/view/Test.java +++ b/MerchantRPGCSE2102/src/view/Test.java @@ -11,10 +11,13 @@ import javax.swing.JSlider; import javax.swing.JLabel; import javax.swing.JButton; +import java.awt.event.ActionListener; +import java.awt.event.ActionEvent; public class Test extends JFrame { private JPanel contentPane; + private JTextField textField; /** * Launch the application. @@ -47,20 +50,21 @@ public Test() { comboBox.setBounds(61, 141, 131, 20); contentPane.add(comboBox); - JSlider slider = new JSlider(); - slider.setBounds(61, 237, 200, 26); - contentPane.add(slider); - JLabel lblSelectTheItem = new JLabel("Select the Item you want:"); lblSelectTheItem.setBounds(61, 105, 168, 14); contentPane.add(lblSelectTheItem); - JLabel lblSelectTheAmount = new JLabel("Select the amount:"); - lblSelectTheAmount.setBounds(61, 197, 131, 14); + JLabel lblSelectTheAmount = new JLabel("Enter the amount you wish to sell:"); + lblSelectTheAmount.setBounds(61, 197, 168, 14); contentPane.add(lblSelectTheAmount); JButton btnAccept = new JButton("Accept"); btnAccept.setBounds(247, 306, 89, 23); contentPane.add(btnAccept); + + textField = new JTextField(); + textField.setBounds(61, 238, 86, 20); + contentPane.add(textField); + textField.setColumns(10); } } diff --git a/MerchantRPGCSE2102/src/view/TransactionUI.java b/MerchantRPGCSE2102/src/view/TransactionUI.java index e018ce1..0db30eb 100644 --- a/MerchantRPGCSE2102/src/view/TransactionUI.java +++ b/MerchantRPGCSE2102/src/view/TransactionUI.java @@ -149,7 +149,7 @@ public void run() @SuppressWarnings({ "unchecked", "rawtypes" }) public static void createSellWindow() { - JFrame frame = new JFrame("Sell"); + final JFrame frame = new JFrame("Sell"); frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); frame.setBounds(100, 100, 600, 600); JPanel contentPane = new JPanel(); @@ -158,31 +158,46 @@ public static void createSellWindow() frame.setContentPane(contentPane); contentPane.setLayout(null); - String[] itemList = new String[MASTER.getPlayer().getInventory().length]; //create a new array of strings with the length of the player's inventory - String chosenItem; //item that the player chooses from the combobox + String[] itemList = new String[MASTER.getPlayer().getInventory().length]; //create a new array of strings with the length of the player's inventory //item that the player chooses from the combobox for(int i = 0; i < itemList.length; i++) //adds all the item names to the item list { itemList[i] = MASTER.getPlayer().getInventory()[i].getItemName(); } - JComboBox comboBox = new JComboBox(itemList); + final JComboBox comboBox = new JComboBox(itemList); comboBox.setBounds(61, 141, 131, 20); contentPane.add(comboBox); - chosenItem = comboBox.getSelectedItem().toString(); - JSlider slider = new JSlider(0, MASTER.searchPlayerInventory(chosenItem).getQuantity(), 0); //sets the slider quantity - slider.setBounds(61, 237, 200, 26); - contentPane.add(slider); + final JTextField textField = new JTextField(); + textField.setBounds(61, 238, 86, 20); + contentPane.add(textField); + textField.setColumns(10); JLabel lblSelectTheItem = new JLabel("Select the Item you want:"); lblSelectTheItem.setBounds(61, 105, 168, 14); contentPane.add(lblSelectTheItem); - JLabel lblSelectTheAmount = new JLabel("Select the amount:"); - lblSelectTheAmount.setBounds(61, 197, 131, 14); + JLabel lblSelectTheAmount = new JLabel("Enter the amount you wish to sell:"); + lblSelectTheAmount.setBounds(61, 197, 168, 14); contentPane.add(lblSelectTheAmount); JButton btnAccept = new JButton("Accept"); + btnAccept.addMouseListener(new MouseAdapter() { + @Override + public void mouseClicked(MouseEvent e) { + String chosenItem = comboBox.getSelectedItem().toString(); + System.out.println(chosenItem); + + try{ + int chosenAmount = Integer.parseInt(textField.getText()); + System.out.println(chosenAmount); + frame.dispose(); + } + catch(NumberFormatException ex){ + System.out.println("Must input a number less than or equal to the total amount of the item that you have"); + } + } + }); btnAccept.setBounds(247, 306, 89, 23); contentPane.add(btnAccept); frame.setVisible(true);