私はスイングするのが初めてです。
このコードでは、カードを表向きにしていますが、一致しないことが判明した場合は、もう一度裏向きに戻します。
現時点で何が起こっているか: 1. 1 枚目のカードをクリックすると裏返る 2. 2 枚目のカードをクリックすると 2 つのいずれかが発生する (a) それらが同じである場合、両方ともそのままであることが望ましい (b) もしそれらは同じではありません.2枚目のカードはカードの裏面をすぐに再表示するため、まったく表示されません(前のカードの裏面も私の方法で定義されています)。
スリープタイマーを入れると、裏返す前に2枚目のカードが表示されたままになるのではないかと思ったのですが、そうではありません。
contentPane.revalidate(); を使用しようとしました。& contentPane.repaint(); しかし、それは何も変わりません。
私はいくつかのコンソール出力を入れました:
Console output:
Card: 0 set
Card: 6 set
Sleeping now
Card: 6 unset
Card: 0 unset
上記は、一致しない 2 つのカードをクリックしたときの結果のコンソール出力です。
@Override
public void actionPerformed(ActionEvent e)
{
String buttonPressed = e.getActionCommand();
int pos = Integer.valueOf(buttonPressed);
action = Control.model.ReceiveCardsTurned(pos);
keypadArray[pos].setIcon(myIcons[pos]);
System.out.println("Card: "+pos+" set");
currentTime.setText("" + Control.model.time);
currentScore.setText("" + Control.model.score);
//contentPane.revalidate();
//contentPane.repaint();
if(Control.model.twoCardsTurned == false)
{
if (action == "unturn")
{
System.out.println("Sleeping now");
try
{
Thread.sleep(1000);
}
catch (InterruptedException e1)
{
e1.printStackTrace();
}
keypadArray[pos].setIcon(back);
keypadArray[Control.model.lastCard].setIcon(back);
System.out.println("Card: "+pos+" unset");
System.out.println("Card: "+Control.model.lastCard+" unset");
}
}
}