diff --git a/MerchantRPGCSE2102/src/view/TransactionUI.java b/MerchantRPGCSE2102/src/view/TransactionUI.java index bd72d3e..2e5ef56 100644 --- a/MerchantRPGCSE2102/src/view/TransactionUI.java +++ b/MerchantRPGCSE2102/src/view/TransactionUI.java @@ -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; @@ -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. */ @@ -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() { @@ -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() { @@ -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() { @@ -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); } /** @@ -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 @@ -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); @@ -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 @@ -206,7 +187,6 @@ public void mouseClicked(MouseEvent e) { //information is consumed whe }); btnAccept.setBounds(247, 306, 89, 23); contentPane.add(btnAccept); - frame.setVisible(true); } /** @@ -214,19 +194,16 @@ public void mouseClicked(MouseEvent e) { //information is consumed whe * 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 @@ -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); @@ -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 @@ -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); } }