From fe0fe238056b51b42ac5e747cc350ce8c41e0f0f Mon Sep 17 00:00:00 2001 From: Gavin Li Date: Mon, 23 Feb 2015 16:17:38 -0500 Subject: [PATCH] Updated Transaction and TransactionUI --- .../src/controller/Transaction.java | 14 +++- .../src/view/TransactionUI.java | 67 +++++++++++++++++-- 2 files changed, 73 insertions(+), 8 deletions(-) diff --git a/MerchantRPGCSE2102/src/controller/Transaction.java b/MerchantRPGCSE2102/src/controller/Transaction.java index 5ff2bcd..b7e507d 100644 --- a/MerchantRPGCSE2102/src/controller/Transaction.java +++ b/MerchantRPGCSE2102/src/controller/Transaction.java @@ -14,7 +14,7 @@ public Transaction(Player player, Merchant targetMerchant) { _player = player; _targetMerchant = targetMerchant; - _window = new TransactionUI(); + _window = new TransactionUI(this); } /** @@ -23,7 +23,7 @@ public Transaction(Player player, Merchant targetMerchant) */ public void runTransaction() { - + _window = new TransactionUI(this); } /** @@ -55,4 +55,14 @@ public boolean actionSell(String itemName, int amount) else return false; } + + /** + * This method will push a true up to the class calling it + * + * @return returns true + */ + public boolean actionCancel() + { + return true; + } } diff --git a/MerchantRPGCSE2102/src/view/TransactionUI.java b/MerchantRPGCSE2102/src/view/TransactionUI.java index 7d67bda..71d4679 100644 --- a/MerchantRPGCSE2102/src/view/TransactionUI.java +++ b/MerchantRPGCSE2102/src/view/TransactionUI.java @@ -3,19 +3,28 @@ import java.awt.BorderLayout; import java.awt.EventQueue; +import javax.swing.BoxLayout; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.border.EmptyBorder; import javax.swing.JButton; import javax.swing.JLabel; + import java.awt.Font; + import javax.swing.JTextField; + +import controller.Transaction; + import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; +import java.awt.event.ActionListener; +import java.awt.event.ActionEvent; public class TransactionUI extends JFrame { private JPanel contentPane; + private static Transaction MASTER; //TransactionUI class will hold the instance of the Transaction that created it /** * Launch the application. @@ -24,7 +33,7 @@ public static void main(String[] args) { EventQueue.invokeLater(new Runnable() { public void run() { try { - TransactionUI frame = new TransactionUI(); + TransactionUI frame = new TransactionUI(MASTER); frame.setVisible(true); } catch (Exception e) { e.printStackTrace(); @@ -36,7 +45,8 @@ public void run() { /** * Create the frame. */ - public TransactionUI() { + public TransactionUI(Transaction master) { + MASTER = master; setTitle("Transaction Window"); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setBounds(100, 100, 600, 430); @@ -45,15 +55,20 @@ public TransactionUI() { setContentPane(contentPane); contentPane.setLayout(null); - JButton btnNewButton = new JButton("BUY"); - btnNewButton.addMouseListener(new MouseAdapter() { + JButton btnBuy = new JButton("BUY"); + btnBuy.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent arg0) { + } + }); + btnBuy.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent arg0) { System.out.println("BUY"); //temporary test code + createBuyWindow(); } }); - btnNewButton.setBounds(58, 155, 169, 105); - contentPane.add(btnNewButton); + btnBuy.setBounds(58, 155, 169, 105); + contentPane.add(btnBuy); JButton btnSell = new JButton("SELL"); btnSell.addMouseListener(new MouseAdapter() { @@ -70,6 +85,7 @@ public void mouseClicked(MouseEvent e) { @Override public void mouseClicked(MouseEvent e) { System.out.println("Cancel"); //temporary test code + exitWindow(); } }); btnCancel.setBounds(246, 344, 89, 23); @@ -85,4 +101,43 @@ public void mouseClicked(MouseEvent e) { lblOr.setBounds(277, 189, 35, 32); contentPane.add(lblOr); } + + /** + * Will exit the transaction window + */ + public void exitWindow() + { + System.exit(0); + } + + /** + * Will create a window for the BUY option + * incomplete method + */ + public static void createBuyWindow() + { + EventQueue.invokeLater(new Runnable() + { + @Override + public void run() + { + JFrame frame = new JFrame("Buy"); + frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); + frame.setBounds(100, 100, 600, 900); + JPanel contentPane = new JPanel(); + contentPane = new JPanel(); + contentPane.setLayout(new BoxLayout(contentPane, BoxLayout.Y_AXIS)); + frame.setVisible(true); + } + }); + } + + /** + * Will create a window for the SELL option + * incomplete method + */ + public static void createSellWindow() + { + + } }