Java system.out.print to print JOptionPane.ShowMessageDialog

后端 未结 3 809
感情败类
感情败类 2021-01-25 15:02

How can I print system.out.print message into a JOptionPane.ShowMessageDialog I need it to run through the for loop and then outside the for loop I need it to display inside of

相关标签:
3条回答
  • 2021-01-25 15:37

    Try to write output to StringBuilder

    StringBuilder sb = new StringBuilder() for (int i = 0; i < numberOfLoans; i++) {

        sb.append(String.format("%d\t%s\t%d   %.2f   %.2f\n", sellingPrice, downPayment, loanAmount, annualInterestRatesArray[i], numberOfYearsArray[i], monthlyPaymentArray[i]));
    
    }
    String toDisplay=sb.toString();
    
    0 讨论(0)
  • 2021-01-25 15:37

    Set the printer used by 'System.out' with your own. Either redirect to a string writer or create your own Printer implementation and use it instead to collect all the printed output in a 'StringBuilder'. Once outside of the loop take the collected 'String' and display it on the dialog.

    I would recommend against using 'System.out.println' altlogether, but I assume you have no other choice.

    0 讨论(0)
  • 2021-01-25 15:40

    Use a StringBuffer.

     StringBuffer sb=new StringBuffer();
     for (int i = 0; i < numberOfLoans; i++) {
          sb.append(your_string);
     }
     JOptionPane.showMessageDialog(parent,sb.toString());
    
    0 讨论(0)
提交回复
热议问题