Skip to content

Commit

Permalink
Updated the actionSell method in TransactionUI
Browse files Browse the repository at this point in the history
  • Loading branch information
Gavin Li committed Feb 25, 2015
1 parent 346b22a commit af58d96
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 16 deletions.
1 change: 1 addition & 0 deletions MerchantRPGCSE2102/src/controller/RPGame.java
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}
16 changes: 10 additions & 6 deletions MerchantRPGCSE2102/src/view/Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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);
}
}
35 changes: 25 additions & 10 deletions MerchantRPGCSE2102/src/view/TransactionUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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);
Expand Down

0 comments on commit af58d96

Please sign in to comment.