2017-07-06 10 views
-1

私の現在のコードは最後に選択されたチェックボックスのみを追加します。私は選択されたチェックボックスからすべての値を取得し、後で印刷するためにjtextareaに追加する必要があります。たぶん配列ですが、配列を追加する方法がわかりません。助けてくれてありがとう!複数のチェックボックスから値を取得し、jtextareaに追加

編集:私はこれを解決しました! appendメソッドに値を渡すのではなく、appendメソッドを値に追加して、目的の出力を得ました。私は更新されたコードを投稿しました。 UPDATED

 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"); 

: ます。private void jBtnRecieptActionPerformed(java.awt.event.ActionEventのEVT){
//ローカル変数に= "" 文字列の項目を宣言します。 int quanity = 0; double priceEa = 0; ダブル合計= 0;

jTextAreaReciept.append("\tFolly Beach Golf:\n"); 

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


    jTextAreaReciept.append("\n\nSubtotal: " + jTextFieldCostofItems.getText() 
      + "\nTax: " + jTextFieldTax.getText() 
      + "\nTotal: " + jTextFieldTotal.getText() 
      + "\n\nDate/Time: " + date + "\n\n\tThank you for your business"); 

答えて

0

このコードを試してみてください。

private void jBtnRecieptActionPerformed(java.awt.event.ActionEvent evt) {            
    //declare local variables 
    String item = ""; 
    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"); 
関連する問題