1
私はシンプルなビデオポーカープログラムを作成しています。今は、ユーザーが保持したいカードを指定した後に実行されたアクションを実行しています。抽選後の新しいカード。私はアクションを持っていますが、私はすべての置換の間に遅れてカードを1つずつ置き換えたいのですが、私が以下に示すコードでは、置き換えなければならないカードの数を500ミリ秒掛けてスリープします。一度に1枚ずつカードを交換するのではなく、一度にカードを交換してください。どんな助けでも大歓迎です!Thread.sleep()に関する問題
Action drawAction = new AbstractAction() {
public void actionPerformed(ActionEvent e) {
int deckPos = 5;
if((holdValFirst.getText()).equals("HELD")){}
else{
holdFirst.setIcon(new ImageIcon(((deck.getDeck())[deckPos]).getCardName()+".gif"));
deckPos++;
try
{
Thread.sleep(500);
}catch (InterruptedException ie){
System.out.println(ie.getMessage());
}
}
if((holdValSecond.getText()).equals("HELD")){}
else{
holdSecond.setIcon(new ImageIcon(((deck.getDeck())[deckPos]).getCardName()+".gif"));
deckPos++;
try
{
Thread.sleep(500);
}catch (InterruptedException ie){
System.out.println(ie.getMessage());
}
}
if((holdValThird.getText()).equals("HELD")){}
else{
holdThird.setIcon(new ImageIcon(((deck.getDeck())[deckPos]).getCardName()+".gif"));
deckPos++;
try
{
Thread.sleep(500);
}catch (InterruptedException ie){
System.out.println(ie.getMessage());
}
}
if((holdValFourth.getText()).equals("HELD")){}
else{
holdFourth.setIcon(new ImageIcon(((deck.getDeck())[deckPos]).getCardName()+".gif"));
deckPos++;
try
{
Thread.sleep(500);
}catch (InterruptedException ie){
System.out.println(ie.getMessage());
}
}
if((holdValFifth.getText()).equals("HELD")){}
else{
holdFifth.setIcon(new ImageIcon(((deck.getDeck())[deckPos]).getCardName()+".gif"));
deckPos++;
}
}
};
コードに重複があります。あなたはおそらく、あなたのすべてのifの "else"部分のためのメソッドを書く必要があります... – phtrivier
[java thread.sleep puts swing ui too sleep]の可能な複製(http://stackoverflow.com/questions/4215968/java-スレッドスリープ - スイング - スリープ - スリープ - あまりにも) –