Skip to content

Commit

Permalink
Updated Transaction and TransactionUI
Browse files Browse the repository at this point in the history
  • Loading branch information
Gavin Li committed Feb 23, 2015
1 parent e69a1c9 commit fe0fe23
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 8 deletions.
14 changes: 12 additions & 2 deletions MerchantRPGCSE2102/src/controller/Transaction.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public Transaction(Player player, Merchant targetMerchant)
{
_player = player;
_targetMerchant = targetMerchant;
_window = new TransactionUI();
_window = new TransactionUI(this);
}

/**
Expand All @@ -23,7 +23,7 @@ public Transaction(Player player, Merchant targetMerchant)
*/
public void runTransaction()
{

_window = new TransactionUI(this);
}

/**
Expand Down Expand Up @@ -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;
}
}
67 changes: 61 additions & 6 deletions MerchantRPGCSE2102/src/view/TransactionUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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();
Expand All @@ -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);
Expand All @@ -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() {
Expand All @@ -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);
Expand All @@ -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()
{

}
}

0 comments on commit fe0fe23

Please sign in to comment.