Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Can't create delay in Applet

 
Tony Higgins
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Bartender
Posts: 5126
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Tony Higgins
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic