jeudi 6 juillet 2017

get value from multiple checkbox's selected and append into jtextarea

My current code will only append the last checkbox selected. I need to get all values from selected checkbox and append into jtextarea to later be printed. Maybe an array but not sure how to append an array. Thanks for any help!

        private void jBtnRecieptActionPerformed(java.awt.event.ActionEvent evt) {                                            
    //declare local variables
    String item = null;
    int quanity = 0;
    double priceEa = 0;
    double total = 0;

    if (jCTiteliestGolfBall.isSelected()) {
        quanity = Integer.parseInt(jQty1.getText());
        item = jCTiteliestGolfBall.getActionCommand();
        priceEa = 1.50;
        total = (priceEa * quanity);
    }
    if (jCTiteliestGolfClubs.isSelected()) {
        quanity = Integer.parseInt(jQty2.getText());
        item = jCTiteliestGolfClubs.getActionCommand();
        priceEa = 150.00;
        total = (priceEa * quanity); 
    }
    if (jCGregNormanGolfShirt.isSelected()) {
        quanity = Integer.parseInt(jQty3.getText());
        item = jCGregNormanGolfShirt.getActionCommand();
        priceEa = 15.00;
        total = (priceEa * quanity);
    }
    if (jCGregNormanGolfHat.isSelected()) {
        quanity = Integer.parseInt(jQty4.getText());
        item = jCGregNormanGolfHat.getActionCommand();
        priceEa = 10.00;
        total = (priceEa * quanity);
    }
    if (jCGolfGlove.isSelected()) {
        quanity = Integer.parseInt(jQty5.getText());
        item = jCGolfGlove.getActionCommand();
        priceEa = 2.00;
        total = (priceEa * quanity);
    }
    if (jCGolfTees.isSelected()) {
        quanity = Integer.parseInt(jQty6.getText());
        item = jCGolfTees.getActionCommand();
        priceEa = .50;
        total = (priceEa * quanity);
    }
    DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy/MM/dd   HH:mm:ss");
    LocalDateTime now = LocalDateTime.now();
    date = (dtf.format(now));


    jTextAreaReciept.append("\tFolly Beach Golf:\n" + item + "   " + quanity + "  @  " 
            +   String.format("%.2f", priceEa) + "  =   " + String.format("%.2f", total) 
            + "\nSubtotal: " + jTextFieldCostofItems.getText()
            + "\nTax: " + jTextFieldTax.getText() 
            + "\nTotal: " + jTextFieldTotal.getText()
            + "\n\nDate/Time:  " + date + "\n\n\tThank you for your business");




Aucun commentaire:

Enregistrer un commentaire