Skip to content

Warning messages are now displayed in windows #19

Merged
merged 1 commit into from
Apr 10, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}
}