File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Applets and the fly likes Can't create delay in Applet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Applets
Bookmark "Can Watch "Can New topic

Can't create delay in Applet

Tony Higgins

Joined: May 28, 2012
Posts: 2
I'm a novice when it comes to Java, and because of that this is my first real application of java that might serve some purpose. I'm trying to recreate the popular handheld game "Simon" within an applet. There is to be four colors that brighten in sequence of what the arraylist "thearray" tells them. The code is rough at this point because I've been trying to create a delay after where the first color is brightened before it returns to its original color, so the user stands a fair chance of inputting the code back in. I was trying to do this originally for the user input, but I worked around that using mousepressed and released instead of clicked. I might be using threads incorrectly, but any study I put into timers simply confused me. Here's my code for the applet and the class that creates the boxes themselves.

and the box class

I apologize for any number of java laws I just broke.
Darryl Burke

Joined: May 03, 2008
Posts: 5115

Don't ever call sleep(...) on the EDT. Use a javax.swing.Timer.

any study I put into timers simply confused me.

Go through the Tutorial, and also the section on Concurrency in Swing.

luck, db
There are no new questions, but there may be new answers.
Tony Higgins

Joined: May 28, 2012
Posts: 2
Okay, so I'm working with javax.swing.Timer, and I think I understand what it's supposed to do, but I don't know how to make it happen. I have a timer created, repeats set to false, and started, but I need the actionlistener to do something, and I don't know how to continue. I need the

in side of the action listener, right? here's what I'm currently working with:

and the method of the action listener

the purpose if for the color to turn brighter, then after a delay return to its original color, and then the next color would do the same.
I agree. Here's the link:
subject: Can't create delay in Applet
It's not a secret anymore!