문제

I'm trying to make a program that models two characters that are racing along a track in a java applet using netbeans. I currently have the racing logic and graphics working fine, but I'm having trouble implementing a delay to show each move the characters make individually.

To create a delay, I currently have this method written:

public void delay()
{

try
            {
            Thread.sleep(500);
            }

catch (InterruptedException ie)
        {
            ie.printStackTrace();
        }

}

However, this causes the program to lag so much that it crashes the appletViewer. How can I delay the system such that it doesn't lag the system?

Thank you for any responses.

도움이 되었습니까?

해결책

Which thread do you call delay()? The UI thread? If it is the case, you may your applet not responsive and break your app. Try the callback function approach.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top