Someone who is a Java developer please reply

Subscribe to Someone who is a Java developer please reply 13 posts

Sign in to reply


 
avatar for gry80 gry80 46 posts
Flag Post

How do I add a Thread.sleep() function to the JFrame’s
public void paint(Graphics g) area?
I know these forums are for Flash programmers but I can’t find anything that says how.

 
avatar for Cloud_9ine Cloud_9ine 2434 posts
Flag Post

Personally I feel that while there are some java programmers, you would have been better off posting on a java board.

 
avatar for gry80 gry80 46 posts
Flag Post

Yeah, but I don’t know of any Java boards.

 
avatar for Jabor Jabor 11382 posts
Flag Post

How do I add a Thread.sleep() function to the JFrame’s
public void paint(Graphics g) area?

The question is, why would you want to?

 
avatar for gry80 gry80 46 posts
Flag Post

I’m making a tower defence game and I need to make it wait before spawning(painting) the next monster.

 
avatar for KMAE KMAE 439 posts
Flag Post

I recall hearing about this before…

This forum will help a lot:

http://forums.sun.com/forum.jspa?forumID=54

You might have to sign up, but it is worth it. I used to ask a lot of questions here when programming Java.

 
avatar for gry80 gry80 46 posts
Flag Post

Ok, thanks.

 
avatar for Jabor Jabor 11382 posts
Flag Post

I’m making a tower defence game and I need to make it wait before spawning(painting) the next monster.

Firstly, you need to realize that creating an object and drawing a picture on the screen are two entirely different things.

Secondly, you don’t want to sleep the whole thread. That would make your application hang (and so the user could do absolutely nothing) until the next unit spawned, at which point it would promptly hang again.

You want to use a timer.

 
avatar for gry80 gry80 46 posts
Flag Post

thanks, but how do I?

 
avatar for Jabor Jabor 11382 posts
Flag Post

You look at the documentation.

http://java.sun.com/javase/6/docs/api/javax/swing/Timer.html

 
avatar for Eketek Eketek 303 posts
Flag Post

It sounds like your jumping the gun on Java – you should probably take the time to learn Java and how games/animations/timed events are usually structured before you make your first game.

Note: You should probably consider using java.lang.Thread instead of javax.swing.Timer.

 
avatar for gry80 gry80 46 posts
Flag Post

I am learning how to use it.

 
avatar for Jabor Jabor 11382 posts
Flag Post

Note: You should probably consider using java.lang.Thread instead of javax.swing.Timer.

…why?

The Swing timer is far better for people new to programming, because it means you can just ignore threads and synchronization entirely. If you stick with the Swing timer, you can code it in much the same way as you would in Flash and it will just work – if you use threads or the Timer class in java.util, you have to keep in mind that anything you ask it to do will be executed on a separate thread, and it will trip you up if you ignore synchronization.

Sign in to reply