Snake Problem

Snake Problem

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.

View Answers

August 23, 2011 at 10:20 AM

hey use threads for the same and it will surely work









Related Tutorials/Questions & Answers:
Snake Problem
Snake Problem  Hello, to one and all.I am trying to develop a snake... it calls t1(thread) in which i have used t1.start() method to allow snake to move right...() method to allow snake to move up. Sample code of run method of this is shown
ModuleNotFoundError: No module named 'Snake'
ModuleNotFoundError: No module named 'Snake'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'Snake' How to remove the ModuleNotFoundError: No module named 'Snake'
Advertisements
ModuleNotFoundError: No module named 'aldryn-snake'
ModuleNotFoundError: No module named 'aldryn-snake'  Hi, My Python... 'aldryn-snake' How to remove the ModuleNotFoundError: No module named 'aldryn-snake' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'py-snake'
ModuleNotFoundError: No module named 'py-snake'  Hi, My Python...-snake' How to remove the ModuleNotFoundError: No module named 'py-snake... to install padas library. You can install py-snake python with following
ModuleNotFoundError: No module named 'python-snake'
ModuleNotFoundError: No module named 'python-snake'  Hi, My Python... 'python-snake' How to remove the ModuleNotFoundError: No module named 'python-snake' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'snake-case'
ModuleNotFoundError: No module named 'snake-case'  Hi, My Python... 'snake-case' How to remove the ModuleNotFoundError: No module named 'snake-case' error? Thanks   Hi, In your python environment you
ModuleNotFoundError: No module named 'snake-gym'
ModuleNotFoundError: No module named 'snake-gym'  Hi, My Python... 'snake-gym' How to remove the ModuleNotFoundError: No module named 'snake... have to install padas library. You can install snake-gym python with following
ModuleNotFoundError: No module named 'snake-pit'
ModuleNotFoundError: No module named 'snake-pit'  Hi, My Python... 'snake-pit' How to remove the ModuleNotFoundError: No module named 'snake... have to install padas library. You can install snake-pit python with following
ModuleNotFoundError: No module named 'Snake-Steak'
ModuleNotFoundError: No module named 'Snake-Steak'  Hi, My Python... 'Snake-Steak' How to remove the ModuleNotFoundError: No module named 'Snake-Steak' error? Thanks   Hi, In your python environment
ModuleNotFoundError: No module named 'camel-and-snake'
ModuleNotFoundError: No module named 'camel-and-snake'  Hi, My... named 'camel-and-snake' How to remove the ModuleNotFoundError: No module named 'camel-and-snake' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'console-snake'
ModuleNotFoundError: No module named 'console-snake'  Hi, My... 'console-snake' How to remove the ModuleNotFoundError: No module named 'console-snake' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'aldryn-snake'
ModuleNotFoundError: No module named 'aldryn-snake'  Hi, My Python... 'aldryn-snake' How to remove the ModuleNotFoundError: No module named 'aldryn-snake' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'aldryn-snake'
ModuleNotFoundError: No module named 'aldryn-snake'  Hi, My Python... 'aldryn-snake' How to remove the ModuleNotFoundError: No module named 'aldryn-snake' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'nevolution-snake'
ModuleNotFoundError: No module named 'nevolution-snake'  Hi, My... named 'nevolution-snake' How to remove the ModuleNotFoundError: No module named 'nevolution-snake' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'py-snake'
ModuleNotFoundError: No module named 'py-snake'  Hi, My Python...-snake' How to remove the ModuleNotFoundError: No module named 'py-snake... to install padas library. You can install py-snake python with following
ModuleNotFoundError: No module named 'py-snake'
ModuleNotFoundError: No module named 'py-snake'  Hi, My Python...-snake' How to remove the ModuleNotFoundError: No module named 'py-snake... to install padas library. You can install py-snake python with following
ModuleNotFoundError: No module named 'python-snake'
ModuleNotFoundError: No module named 'python-snake'  Hi, My Python... 'python-snake' How to remove the ModuleNotFoundError: No module named 'python-snake' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'python-snake'
ModuleNotFoundError: No module named 'python-snake'  Hi, My Python... 'python-snake' How to remove the ModuleNotFoundError: No module named 'python-snake' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'rocket-snake'
ModuleNotFoundError: No module named 'rocket-snake'  Hi, My Python... 'rocket-snake' How to remove the ModuleNotFoundError: No module named 'rocket-snake' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'snake-eyes'
ModuleNotFoundError: No module named 'snake-eyes'  Hi, My Python... 'snake-eyes' How to remove the ModuleNotFoundError: No module named 'snake-eyes' error? Thanks   Hi, In your python environment you
ModuleNotFoundError: No module named 'snake-guice'
ModuleNotFoundError: No module named 'snake-guice'  Hi, My Python... 'snake-guice' How to remove the ModuleNotFoundError: No module named 'snake-guice' error? Thanks   Hi, In your python environment
ModuleNotFoundError: No module named 'snake_nupic'
ModuleNotFoundError: No module named 'snake_nupic'  Hi, My Python... 'snake_nupic' How to remove the ModuleNotFoundError: No module named 'snake_nupic' error? Thanks   Hi, In your python environment
ModuleNotFoundError: No module named 'snake-on-pygame'
ModuleNotFoundError: No module named 'snake-on-pygame'  Hi, My... named 'snake-on-pygame' How to remove the ModuleNotFoundError: No module named 'snake-on-pygame' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'aldryn-snake'
ModuleNotFoundError: No module named 'aldryn-snake'  Hi, My Python... 'aldryn-snake' How to remove the ModuleNotFoundError: No module named 'aldryn-snake' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'curses-snake'
ModuleNotFoundError: No module named 'curses-snake'  Hi, My Python... 'curses-snake' How to remove the ModuleNotFoundError: No module named 'curses-snake' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'frigga-snake'
ModuleNotFoundError: No module named 'frigga-snake'  Hi, My Python... 'frigga-snake' How to remove the ModuleNotFoundError: No module named 'frigga-snake' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'snake_progress_bar'
ModuleNotFoundError: No module named 'snake_progress_bar'  Hi, My... named 'snake_progress_bar' How to remove the ModuleNotFoundError: No module named 'snake_progress_bar' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'snake-rl-melanol'
ModuleNotFoundError: No module named 'snake-rl-melanol'  Hi, My... named 'snake-rl-melanol' How to remove the ModuleNotFoundError: No module named 'snake-rl-melanol' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'snake-terminal-pp'
ModuleNotFoundError: No module named 'snake-terminal-pp'  Hi, My... named 'snake-terminal-pp' How to remove the ModuleNotFoundError: No module named 'snake-terminal-pp' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'camel_snake_kebab'
ModuleNotFoundError: No module named 'camel_snake_kebab'  Hi, My... named 'camel_snake_kebab' How to remove the ModuleNotFoundError: No module named 'camel_snake_kebab' error? Thanks   Hi, In your
plz help me to write a snake game using swings - Swing AWT
plz help me to write a snake game using swings  write snake game program using swings
genaral snake game in java - Java Beginners
genaral snake game in java  can u please send code for fallowing write a snake game program using swings?  Hi This is the source code of Snake game in swing Snake.java file import javax.swing.JFrame
Problem in coding - Java Beginners
Problem in coding  How many times do you have to roll a pair of dice before they come up snake eyes? You could do the experiment by rolling the dice... should report the number of rolls that it makes before the dice come up snake eyes
problem in onlinetest...
problem in onlinetest...  hi, my code getting the problem is ,when user leave a question then the server puts error... pls help me
problem in validation
problem in validation  sir/madam, i m using struts-1.3.10. i m getting a problem my properties file is not found.... while i hav configuired it in struts-config.xml file, likeADS_TO_REPLACE_1 thanks n regards himanshu
javascript problem
javascript problem  hi guys My problem is that I am using radio button for yes or no but i want to do that if I press yes button then enter... enter please help me this problem
problem on strings
problem on strings  in string1 "123456 ABC DEF...",IN string2 "raveen". iwant to add string2 after 123456 in the first string based on index number.i need logic for this with out using StringBuffer concept. Thanks in advanace
Problem with loginbean.jsp
Problem with loginbean.jsp  http://www.roseindia.net/jsp/loginbean.shtml - I am getting an error in loginbean.jsp.There is some error regarding .What is hello in this? Also in this example how
compilation problem
compilation problem  struts 2.0 : i have included all 5 jars in lib folder,but its giving compilation problem that package open symphony doesnot... havenot set the build path.if this is the problem then tell me how to set
compilation problem
compilation problem  struts 2.0 : i have included all 5 jars in lib folder,but its giving compilation problem that package open symphony doesnot... havenot set the build path.if this is the problem then tell me how to set
Problem with cookies
Problem with cookies  Hello All, i need jsp code for RememberMe module of login. i am facing problem with cookies. so please if any one could guide me please help and provide mme the exact code.   Please visit
problem with package
problem with package  Dear sir, i have created one java file with package com.net; and i compiled the program.it showing the .class file in " net" folder.The problem is i want to use that .class file in some other
Oracle9i Problem
Oracle9i Problem  Hi I have a problem in Oracle9i .I have... the table what i created .But after closing the SQL+ ,the problem started.When i... .....;.it is saying no rows are selected.Why the problem arised in not getting the data that i
problem with session.invalidate()
problem with session.invalidate()  i stuck by a line with "session.invalidate()", after user logout also by pressing the back button of the browser user is still able to navigate to his home page and able to view the session
JScrollBar Problem...
JScrollBar Problem...  Hello Sir/mam, Can i know how to use JScrollBar to JFrame without adding any JPanel to it.. i want to add JScrollBar Directly to JFrame... Please Provide me Simple Example so i can understand
problem on php
problem on php   l have five tables and build them as forms and link between them php and database and i want to build query between them plz help me soon   PHP MySQL Tutorials
URL problem
URL problem  Hi. I have created a webpage for my project website. in that i have used frameset to split the page. Now if i click any link in the page its navigating to the another page. but the problem is here in the url its
Is AI a problem?
Is AI a problem?  Hi, I am beginner in Data Science and machine learning field. I am searching for the tutorials to learn: Is AI a problem? Try... "Is AI a problem?". Also tell me which is the good training courses
Skyline Problem
is the line tracing the largest y value from any rectangle in S The Problem: Write.... Your method should solve the problem three different ways; each solution
Problem in Array
Problem in Array  Hi, Can you help me with this problem? Run a program that check if the input string contains equal number of A's and B's. Hoping for your answer.Thank you.   Here is an example that check

Ads