Skip to content

Commit

Permalink
Committing changes made to TransactionUI. The transaction is now cont…
Browse files Browse the repository at this point in the history
…ained within one window only.
  • Loading branch information
john committed Mar 7, 2015
1 parent 0d9fc39 commit ba32595
Showing 1 changed file with 44 additions and 59 deletions.
103 changes: 44 additions & 59 deletions MerchantRPGCSE2102/src/view/TransactionUI.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,9 @@
package view;

import java.awt.EventQueue;

import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JRootPane;
import javax.swing.border.EmptyBorder;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.*;

import java.awt.Font;

import javax.swing.JTextField;
import javax.swing.border.EmptyBorder;

import controller.Transaction;
import exceptions.MerchantNotEnoughCashException;
Expand All @@ -26,26 +17,10 @@
@SuppressWarnings("serial")
public class TransactionUI extends JFrame {

private JPanel contentPane;
private 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

/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
TransactionUI frame = new TransactionUI(MASTER);
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}

/**
* Create the frame.
*/
Expand All @@ -55,10 +30,9 @@ public TransactionUI(Transaction master) {
setTitle("Transaction Window");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 600, 430);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
transactionPanel = new JPanel();
transactionPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
transactionPanel.setLayout(null);

JButton btnBuy = new JButton("BUY"); //creates a "Buy" button
btnBuy.addActionListener(new ActionListener() {
Expand All @@ -74,7 +48,7 @@ public void mouseClicked(MouseEvent arg0) {
}
});
btnBuy.setBounds(58, 155, 169, 105);
contentPane.add(btnBuy);
transactionPanel.add(btnBuy);

JButton btnSell = new JButton("SELL"); //creates a "Sell" button
btnSell.addMouseListener(new MouseAdapter() {
Expand All @@ -86,7 +60,7 @@ public void mouseClicked(MouseEvent e) {
}
});
btnSell.setBounds(351, 155, 169, 105);
contentPane.add(btnSell);
transactionPanel.add(btnSell);

JButton btnCancel = new JButton("End Transaction"); //creates a button to end the transaction
btnCancel.addMouseListener(new MouseAdapter() {
Expand All @@ -101,17 +75,19 @@ public void mouseClicked(MouseEvent e) {
}
});
btnCancel.setBounds(210, 310, 160, 50);
contentPane.add(btnCancel);
transactionPanel.add(btnCancel);

JLabel lblWouldYouLike = new JLabel("Would you like to:");
lblWouldYouLike.setFont(new Font("Tahoma", Font.PLAIN, 15));
lblWouldYouLike.setBounds(233, 76, 193, 32);
contentPane.add(lblWouldYouLike);
transactionPanel.add(lblWouldYouLike);

JLabel lblOr = new JLabel("OR");
lblOr.setFont(new Font("Tahoma", Font.PLAIN, 15));
lblOr.setBounds(277, 189, 35, 32);
contentPane.add(lblOr);
transactionPanel.add(lblOr);
add(transactionPanel);
setLocationRelativeTo(null);
}

/**
Expand All @@ -127,19 +103,17 @@ public void exitWindow()
* Will create a window for the BUY option
* INCOMPLETE METHOD
*/
public static void createBuyWindow()
public void createBuyWindow()
{
_inTransaction = true; //does not allow new transaction windows to be opened while buy window is
final JFrame frame = new JFrame("Buy");
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
frame.setBounds(100, 100, 400, 400);
frame.setUndecorated(true);
frame.getRootPane().setWindowDecorationStyle(JRootPane.NONE);
JPanel contentPane = new JPanel();
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
frame.setContentPane(contentPane);
contentPane.setLayout(null);
getContentPane().removeAll();
add(contentPane);
setVisible(false);
setVisible(true);
setVisible(true);

String[] itemList = new String[MASTER.getTargetMerchant().getInventory().length]; //create a new array of strings with the length of the player's inventory
for(int i = 0; i < itemList.length; i++) //adds all the item names to the item list
Expand Down Expand Up @@ -175,7 +149,10 @@ public static void createBuyWindow()
@Override
public void mouseClicked(MouseEvent arg0) {
_inTransaction = false;
frame.dispose();
getContentPane().removeAll();
add(transactionPanel);
setVisible(false);
setVisible(true);
}
});
btnCancel.setBounds(61, 306, 89, 23);
Expand All @@ -194,7 +171,11 @@ public void mouseClicked(MouseEvent e) { //information is consumed whe
{
System.out.println(chosenAmount);
_inTransaction = false;
frame.dispose();
getContentPane().removeAll();
add(transactionPanel);
setVisible(false);
setVisible(true);
dispose();
}
else
throw new NumberFormatException(); //will throw a NumberFormatException if actionBuy returns a false
Expand All @@ -206,27 +187,23 @@ public void mouseClicked(MouseEvent e) { //information is consumed whe
});
btnAccept.setBounds(247, 306, 89, 23);
contentPane.add(btnAccept);
frame.setVisible(true);
}

/**
* Will create a window for the SELL option
* INCOMPLETE METHOD: Still needs to integrate with the transaction limit in the daily cycle
*/
@SuppressWarnings({ "unchecked", "rawtypes" })
public static void createSellWindow()
public void createSellWindow()
{
_inTransaction = true; //does not allow new transaction windows to be opened if sell window is
final JFrame frame = new JFrame("Sell");
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
frame.setBounds(100, 100, 400, 400);
frame.setUndecorated(true);
frame.getRootPane().setWindowDecorationStyle(JRootPane.NONE);
JPanel contentPane = new JPanel();
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
frame.setContentPane(contentPane);
contentPane.setLayout(null);
getContentPane().removeAll();
add(contentPane);
setVisible(false);
setVisible(true);

String[] itemList = new String[MASTER.getTargetMerchant().getInventory().length]; //create a new array of strings with the length of the player's inventory
for(int i = 0; i < itemList.length; i++) //adds all the item names to the item list
Expand Down Expand Up @@ -262,7 +239,10 @@ public static void createSellWindow()
@Override
public void mouseClicked(MouseEvent arg0) {
_inTransaction = false;
frame.dispose();
getContentPane().removeAll();
add(transactionPanel);
setVisible(false);
setVisible(true);
}
});
btnCancel.setBounds(61, 306, 89, 23);
Expand All @@ -285,7 +265,11 @@ public void mouseClicked(MouseEvent e) { //information is consumed w
{
System.out.println(chosenAmount);
_inTransaction = false;
frame.dispose();
getContentPane().removeAll();
add(transactionPanel);
setVisible(false);
setVisible(true);
dispose();
}
else
throw new NumberFormatException(); //will throw a NumberFormatException if actionSell returns a false
Expand All @@ -305,6 +289,7 @@ public void mouseClicked(MouseEvent e) { //information is consumed w
});
btnAccept.setBounds(247, 306, 89, 23);
contentPane.add(btnAccept);
frame.setVisible(true);
// frame.setVisible(true);
// frame.setLocationRelativeTo(null);
}
}

0 comments on commit ba32595

Please sign in to comment.