我正在爲uni任務做一個撲克遊戲,我想知道是否有任何方法有如下方法(注意:非常粗略的代碼)任何方式來延遲在Java GUI中的操作
JTextArea textArea = new JTextArea();
public void printer(String s){
//I want to delay here, for 2 seconds each time i print to the jtextarea
textArea.append(s);
}
public void runGame(){
printer("Dealing cards...");
//I want to delay to add to an effect of the time it takes to actually deal the cards
pokerHand.setVisibility(true);
printer("What you like to do?");
//
//Code here containing running the game
//
printer("Daniel Negreanu folds");
//I want to have a delay here for the time it takes to make a decision.
printer("Phil Hellmuth folds");
Theres許多更多的實例,我想在整個程序中使用它,只是想知道是否有任何方法可以做到這一點。
在此先感謝
編輯:不希望使用Thread.sleep()方法,因爲它不貴很好地工作。 編輯2:我想pokerHand.setVisibility(true)和其他方法在我的代碼中執行延遲後(使用定時器不執行此操作)。
Thread.sleep(2000)將整個gui暫停2秒,稍微凍結它,它不是我正在尋找,編輯的內容。無論如何,謝謝 –
@ cricket_007他們使用的方法會延遲消息,但不會延遲其他代碼的運行,例如,計時器將暫停printer()方法,pokerHand.setVisibility(true)會毫無延遲地執行。 –
然後,您在代碼 –