So I'm making a mock Starbucks app and I want that everytime a customer clicks the "Order" button, the product is added to an ArrayList and for this ArrayList to be accessed by all. I'm kind of confused where to insert the global ArrayList code...
This is code for my btnOrder:
private void btnOrderActionPerformed(java.awt.event.ActionEvent evt) {
String name = lblName.getText();
String size = cmbSize.getSelectedItem().toString();
int quantity = (int) spnrQuantity.getValue();
int price=0;
if (size.equals("Tall 12oz")) {
price = 170;
} else if (size.equals("Grande 16oz")) {
price = 180;
} else if (size.equals("Venti 20oz")) {
price = 190;
}
Global.list.add(new Object());
new Receipt(name, size, quantity, price).setVisible(true);
}
This is code for my Receipt frame which contains the JTable so I can display orders:
public class Receipt extends javax.swing.JFrame {
/**
* Creates new form Receipt
*/
public Receipt() {
initComponents();
}
String size, name;
int quantity, price;
public Receipt(String name, String size, int quantity, int price) {
initComponents();
this.name = name;
this.size = size;
this.quantity = quantity;
this.price = price;
addToTable();
}
void addToTable() {
DefaultTableModel table = (DefaultTableModel) tblCart.getModel();
Vector v = new Vector();
v.add(name);
v.add(size);
v.add(price);
v.add(quantity);
table.addRow(v);
}
And this is the code for the accessible ArrayList:
public class Global {
public static ArrayList<Object> list = new ArrayList<>();
private Global(){
}
}