Results 1 to 5 of 5
Thread: Any clever solution?
- 10-02-2011, 11:12 AM #1
Member
- Join Date
- Sep 2011
- Posts
- 10
- Rep Power
- 0
Any clever solution?
I want to draw a simple animation, a huge problem would be, as we all know, today's computer are lightening fast, so if I do a loop, I'll have to use the thread.sleep method.
I think this method, though textbook-simple, is still pointless. I mean why wasting all those precious CPU time on something completely meaningless?
So what I'm thinking is to pull something like a timer or some sort, an "active" timer, when the timer hit its set value, it tells the program to draw a new frame actively and positively, and during this period, the program can do something else, if there is something else to do.
You don't have to provide no code, all I'm asking is a clue, a lead, a link or the name of a framework or a library.
Thanks in advance!
- 10-02-2011, 11:25 AM #2
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,606
- Blog Entries
- 7
- Rep Power
- 17
Re: Any clever solution?
Bookmark (or even better: download) the Java SE API documentation and read about the several Timer classes; you define an interval time and a piece of code to be run and give it to a Timer object; at regular intervals your piece of code will be run so it can make your GUI draw a next image or whatever.
kind regards,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
- 10-02-2011, 11:26 AM #3
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,561
- Rep Power
- 11
Re: Any clever solution?
Swing includes a Timer class which this. You create a timer which "ticks" every n milliseconds and you tell the timer what action to perform on each tick.
Look for "timer" in Oracle's JavaTutorial.
- 10-03-2011, 02:23 AM #4
Member
- Join Date
- Sep 2011
- Posts
- 10
- Rep Power
- 0
Re: Any clever solution?
Thanks, esp. JosAH, hope you don't mind being bombarded with these stupid questions.
- 10-03-2011, 03:51 AM #5
- Join Date
- Jan 2011
- Location
- Richmond, Virginia
- Posts
- 3,069
- Blog Entries
- 3
- Rep Power
- 7
Re: Any clever solution?
I don't mind questions, and I'm sure others don't. If you'd like a fairly decent tutorial to get you a bit familiar with some animations, check out: Programing An Applet Game Of Pong - Java Tutorials | Dream.In.Code
It's a fairly good tutorial, some things to consider if you do this:
1. Define only one class for both paddles(abstract the class).
2. Don't use setters in the constructor, and avoid recursive calls in the setter(it's unnecessary).
3. Draw on a buffered image and make it work on a JPanel instead of an applet.
It's a pretty good exercise and should be simple enough to follow and will give you some good ideas for later projects.
Similar Threads
-
Clever glimpse needed with this recursion
By Yakg in forum New To JavaReplies: 14Last Post: 02-10-2011, 09:15 PM -
A clever way of doing this ... (avoiding a LOT of if-else statements)
By doejohn in forum New To JavaReplies: 3Last Post: 07-01-2010, 08:39 PM -
Please I need the solution to this
By debobbt in forum New To JavaReplies: 4Last Post: 12-18-2009, 04:34 AM -
Please give me a solution
By ivvgangadhar in forum AWT / SwingReplies: 5Last Post: 11-14-2008, 01:43 PM -
Please need solution
By prithvi in forum New To JavaReplies: 4Last Post: 04-22-2008, 01:27 PM


1Likes
LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks