我正在編寫一個程序,其中我將一個名稱與一個列表進行匹配。如果我沒有找到匹配項,我在SQLite數據庫上查找名稱,將名稱信息提取到文本字段中,然後顯示該卡(cardlayout)。當我運行這個時,我只能得到最後一次不匹配的信息。在研究這個時,我想我可以使用SwingWorker來解決這個問題。我把我的做,並把它放在一個SwingWorker類,並添加一個發佈()我想顯示的信息。我得到相同的結果,只顯示最後一個不匹配。Java SwingWorker未按預期工作
這裏是我的代碼片段:
public class processTeeTimes extends SwingWorker <Integer, String>
{
@Override
protected Integer doInBackground() throws Exception
{
// Process all tee times foursome at a time
String memberGuest; // Member or guest
do // Process players in foursome
{
.
.
.
if (!firstOnGHIN())
{
System.out.print("No match - first (" + tsTime + "): ");
printGolfer(); // Print no match
publish(golfer[0]);
}
.
.
.
}
while (!EOF)
}
@Override
protected void process(List<String> golferList)
{
for (int gIndex = 0; gIndex < golferList.size(); gIndex++)
{
textFieldRMLast.setText(golferList.get(gIndex));
cards.show(panelCont, ROSTERMAINT); // Show roster maint card
}
}
@Override
protected void done()
{
.
.
.
System.out.println("All done processing Tee Sheet");
}
任何幫助,將不勝感激。
我們不能編譯也不能運行代碼片段,我們不希望整個代碼庫。相反,我強烈建議您創建併發布有效的[mcve] - 請閱讀鏈接。 –