我不知道这是否可能。我正在制作一个彩票应用程序,并且尝试使用尽可能少的 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);
您可以猜到,我希望 JTextArea 更新,因为我在上面的 for 循环中设置了 textArea 的文本。它直到方法结束才更新 JTextArea,这是我设置文本区域以显示工单报告时的最底部。
我的最终目标:我想最终把它变成一个 Android 手机应用程序,所以这就是我不想使用任何弹出窗口或任何东西的原因。