• Post Reply Bookmark Topic Watch Topic
  • New Topic

New to java

 
chaitanya karthikk
Ranch Hand
Posts: 806
Java MySQL Database Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi I am chaitanya, can anybody tell me how to learn more about java threads. I want to develop a game using applet where there is a gun firing bullets. Can anybody suggest me where can I find solutions and where can i get about threads in detail.
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can start by reading this
http://java.sun.com/docs/books/tutorial/essential/concurrency/

If you are looking for ready made solutions, you are at the wrong place. We do not hand out code here at the ranch.
From your question, I presume you want to display the bullet trajectory.
For that to work you will need to play with the paintComponent(Graphics g) of the container, typically a JPanel.
More about basics of custom painting can be found here http://java.sun.com/products/jfc/tsc/articles/painting/
Also notice the "The Paint Methods" section in the article.
 
chaitanya karthikk
Ranch Hand
Posts: 806
Java MySQL Database Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Maneesh, I have all the maths do this, but when coming to programming, I am able to fire the first bullet and move my gun, the actual problem comes when firing the second bullet. I found that I am doing wrong in handling threads. So I thought to learn threads in detail. Thank you for your quick reply.
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok. Looks like your problem is more related to threading. We have a dedicated forum for Threads. Do you want me to move this post there for you?
 
chaitanya karthikk
Ranch Hand
Posts: 806
Java MySQL Database Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Maneesh, Please move it to the related forum.
 
shadi azouri
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dont get too complicated, you could do this with one animation Thread that handles all movement of objects in a cycle with a timed delay:

Given a List of objects, each one of which has a current position, velocity and pointer to the image to use:

1. move all objects according to the physics
2. paint the new display
3. timed wait with Thread sleep
4. check to see if we have been told to stop.

The user thread which responds to user events should only be used to create new objects in the List and provide for eventually stopping the animation thread.

(Man this takes me back, my first big applet did an animated display of a baseball game!)

Bill
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!