これが可能かどうかはわかりません。私は宝くじアプリケーションを作成しており、できるだけ少ない GUI コンポーネントを使用しようとしています。したがって、次のメッセージを表示するはずの JTextArea があります(たとえば):
「計算中…55.4%」
コンソールに出力すると問題なく表示されますが、JTextArea には出力されません。SwingUtilities.invokeLater を使用しようとしましたが、それも機能しません。
for (int x = 0; x < daysBetween; x++)
{
completion = "Calculating..." + df.format((100 * (x + 1)) / daysBetween) + "%";
if (!textArea.getText().equals(completion))
{
textArea.setText(completion);
}
/*
Here I have a lot of irrelevant code that compares your tickets to the winning tickets and counts your winnings and other statistics...
*/
}
ticketReport += "Computation time: " + getElapsedTime(start, System.nanoTime());
ticketReport += "\nEnd date: " + (cal.get(Calendar.MONTH) + 1) + "/" + cal.get(Calendar.DAY_OF_MONTH) + "/" + cal.get(Calendar.YEAR);
ticketReport += "\nTotal # of tickets purchased: " + numOfTicketsPurchased;
/*
etc. with filling out the ticket report
*/
textArea.setText(ticketReport);
ご想像のとおり、上記の for ループで textArea のテキストを設定すると、JTextArea が更新されます。メソッドの最後まで JTextArea を更新しません。これは、チケット レポートを表示するようにテキスト領域を設定したときの一番下です。
最終目標: 最終的にはこれを Android フォン アプリケーションにしたいので、ポップアップなどは一切使用したくありません。