
Hello, to one and all.I am trying to develop a snake game using J2ME and its almost finish but in this apps i have used multiple threads ,each key press causes an event to start. Which means when i press 6 it calls t1(thread) in which i have used t1.start() method to allow snake to move right. Similarly, when i press 2 it calls t2(thread) in which i have used t2.start() method to allow snake to move up. Sample code of run method of this is shown below:
while(startX!=getWidth()-2 && Right==true)
//end of row earlier here was (While)
{
if(Last_num!=6)
// six was not the last key pressed
{
// if((startX+1) is not red)
{
repaint();
serviceRepaints();
setDefault();
Right=true;
tail();
}
But when i again press 6 after pressing 2 my midlet throws an Exception(java.lang.IlligalThreadState Exception). I also tried to use try and catch block but it is not working. I want to stop the previous thread when i call the next. Please Help its very Important. I will be very thankful. please reply.

hey use threads for the same and it will surely work
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.