Using a timer to paint an oval

F

Fred Bassett

Hi,

I'm teaching myself Java and can't seem to find the answer of my question
anywhere, it's a real noob question, but I will still ask.

I would like to create an applet (or application) that uses a timer to paint
an oval every 2 seconds. Every time a new oval is painted it will be in a
new position (i.e. x + 2 and y + 2).

I'm having difficulties getting a timer to repaint my oval each time.

Does anyone have any example code they could share with me please? Or know
of a tutorial that might help me? I really just want to learn how to
understand timers better so I can use them for more advanced things.

Thank you, Fred
 
A

Andrew Thompson

I'm teaching myself Java and can't seem to find the answer of my question
anywhere,

Where were you looking? What search terms did you try?
..it's a real noob question,

Folks who are learning Java are best helped on a different group.
...but I will still ask.

I would like to create an applet (or application)

Make an *application* first, either way.
.. that uses a timer ..

Is that a java.util.Timer? A javax.swing.Timer?
When discussing Java please try to be very specific, and use
correct capitalisation of class/method names to help others
to understand you.
..to paint
an oval every 2 seconds. Every time a new oval is painted it will be in a
new position (i.e. x + 2 and y + 2).

I'm having difficulties getting a timer to repaint my oval each time.

With what code? said:
Does anyone have any example code they could share with me please?

I have some examples using threads..
<http://www.physci.org/codes/display.jsp?fmt=raw&fl=/codes/AnimateBalls/AnimateFrame.java>
...and a swing version.
..Or know of a tutorial that might help me?

There seem to be two separate issues here..
Timing things to happen when you want, and painting.
It sounds as though you are OK with the painting (though
you have not given much detail) so I assume it is more the
threading?

Errmmm.. try these two..
<http://java.sun.com/docs/books/tutorial/essential/threads/index.html>
<http://java.sun.com/developer/codesamples/thrds.html>

HTH
 
R

Robot18F

Here are some examples I found by doing a google search for "Java
Animation Tutorial"

http://www.javaworld.com/javaworld/jw-03-1996/jw-03-animation.html
http://www.javaworld.com/jw-03-1996/animation/
http://www.dickbaldwin.com/java/Java172.htm

or google for "Java Timer Tutorial"

http://java.sun.com/docs/books/tutorial/essential/threads/timer.html
http://java.sun.com/docs/books/tutorial/uiswing/misc/timer.html
http://www.developertutorials.com/tutorials/java/recurring-java-tasks/page1.html

There are hundreds of tutorials on-line, you just have to specify what
your looking for. I'm new to Java myself, but most everything I have
learned I've found on-line.
 
A

Andrew Thompson

...or google for "Java Timer Tutorial"

Great idea.
..I'm new to Java myself, but most everything I have
learned I've found on-line.

Google's great huh? A lot of people are not good at googling
and those that are often forget to include tips in posts.
You should post more often.
 
F

Fred Bassett

Thank you both for your help. As I am unfamiliar with researching Java I
think I was searching Google with the wrong words!

The animation tutorials are particularly helpful! I'm experimenting with
the code now! :eek:)

Thanks, Fred
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,777
Messages
2,569,604
Members
45,223
Latest member
Jurgen2087

Latest Threads

Top