Skip to content

Commit

Permalink
Merge pull request #19 from gal11002/Gavin-L
Browse files Browse the repository at this point in the history
Warning messages are now displayed in windows
  • Loading branch information
gal11002 committed Apr 10, 2015
2 parents a9aedf2 + afd2d9e commit 76b5727
Showing 1 changed file with 34 additions and 3 deletions.
37 changes: 34 additions & 3 deletions MerchantRPGCSE2102/src/view/TransactionUI.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package view;

import java.awt.EventQueue;
import java.awt.FlowLayout;

import javax.swing.JComboBox;
import javax.swing.JFrame;
Expand All @@ -26,7 +27,7 @@
@SuppressWarnings("serial")
public class TransactionUI extends JFrame {

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

Expand Down Expand Up @@ -201,6 +202,7 @@ public void mouseClicked(MouseEvent e) { //information is consumed whe
}
catch(NumberFormatException exception){
System.out.println("Must input an amount that you can afford");
createWarning("Must input an amount that you can afford");
}
}
});
Expand Down Expand Up @@ -292,19 +294,48 @@ public void mouseClicked(MouseEvent e) { //information is consumed w
}
catch(MerchantNotEnoughCashException mnecexception){
System.out.println("Merchant does not have enough cash");
createWarning("Merchant does not have enough cash");
}
}
catch(NumberFormatException exception){
System.out.println("Must input a number less than or equal to the total amount of the item that you have");
System.out.println("You do not have enough of that item");
createWarning("You do not have enough of that item");
}
}
catch(NotInInventoryException niiexception){
System.out.println("Merchant does not accept that item");;
System.out.println("Merchant does not accept that item");
createWarning("Merchant does not accept that item");
}
}
});
btnAccept.setBounds(247, 306, 89, 23);
contentPane.add(btnAccept);
frame.setVisible(true);
}

public static void createWarning(String message) {
final JFrame contentFrame = new JFrame();
contentFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
contentFrame.setBounds(100, 100, 450, 300);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
contentFrame.setContentPane(contentPane);
contentPane.setLayout(null);

JButton btnOk = new JButton("Ok");
btnOk.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent arg0) {
_inTransaction = false;
contentFrame.dispose();
}
});
btnOk.setBounds(162, 203, 103, 32);
contentPane.add(btnOk);

JLabel lblNewLabel = new JLabel(message);
lblNewLabel.setBounds(80, 102, 265, 49);
contentPane.add(lblNewLabel);
contentFrame.setVisible(true);
}
}

0 comments on commit 76b5727

Please sign in to comment.