0

Hey I want to simulate a knight moving in my Knight Tour Gui,

this is the display code, the moves are stored in the arraylist moves.

public void display()
	{
		for(int i = 0; i < moves.size(); i++)
		{
			//Gets the correct button
			JButton button = square.get(moves.indexOf(i+1));
			
			button.setText("" + i);
		}
	}

I had something like this, but wasnt implementing the timer correctly I think because it didnt work.

Any help on this or other ways to do it

public void display()
	{
		timer = new Timer(2000, new ActionListener() {
		    public void actionPerformed(ActionEvent evt) {
		    	
		    }});
		for(int i = 0; i < moves.size(); i++)
		{
			//Gets the correct button
			JButton button = square.get(moves.indexOf(i+1));
			
			timer.setDelay(1500);
			
			button.setText("" + i);
		}
	}
2
Contributors
1
Reply
2
Views
7 Years
Discussion Span
Last Post by adams161
0

you mentioned making it sleep

you will need import java.lang.Thread.*;


and

Thread.sleep(1000);

put in the program at any line, will make it sleep 1 second or 1000 milliseconds. The program tells the operating system, i'm done for now, come back to me in 1000 ms.

Mike

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.