private void emptyButtonActionPerformed( java.awt.event.ActionEvent evt) { // GEN-FIRST:event_emptyButtonActionPerformed // Clears the arraylist therefore clearing the inventory. Inventory.clear(); updateTable(); pipesInfoOutput.setText("Basket has been cleared."); } // GEN-LAST:event_emptyButtonActionPerformed
private void basketTableMousePressed( java.awt.event.MouseEvent evt) { // GEN-FIRST:event_basketTableMousePressed /* When the selected row is double clicked. It is removed from the arraylist and the table is updated. */ JTable selected = (JTable) evt.getSource(); int row = selected.getSelectedRow(); if (evt.getClickCount() == 2) { Inventory.remove(row); updateTable(); } else if (evt.getClickCount() == 1) { Pipes[] specificPipe = Inventory.toArray(new Pipes[Inventory.size()]); pipe = specificPipe[row]; getPipeInfo(); } } // GEN-LAST:event_basketTableMousePressed
private void addToBasketActionPerformed( java.awt.event.ActionEvent evt) { // GEN-FIRST:event_addToBasketActionPerformed // Adds the selected valid pipe to the arraylist. int inQuantity = 0; boolean quantityVal = false; pipesInfoOutput.setText(""); // If a valid pipe is found if (findValidPipe() == true) { // Validates the quantity input. try { inQuantity = Integer.parseInt(quantityTF.getText()); if (inQuantity < 1.0 || inQuantity > 20.0) { pipesInfoOutput.setText(""); validationMessages("Quantity", 1.0, 20.0); } else { quantityVal = true; } } catch (NumberFormatException e) { System.err.println(e); pipesInfoOutput.setText(""); validationMessages("QuantityR", 0, 0); } /* Adds the valid pipe to an arraylist a set amount of times as defined by the quantity variable */ if (quantityVal == true) { for (int x = 0; x < inQuantity; x++) { // Checks that the basket is not full if (Inventory.size() < 50) { Inventory.add(pipe); } else { pipesInfoOutput.setText( "Error Add to Basket: " + "Basket Full." + "\nQuantiy of Pipes in Basket: " + Inventory.size()); } } ; updateTable(); } } } // GEN-LAST:event_addToBasketActionPerformed