Timer Help

publicclass ButtonHandlerimplements ActionListener{

publicvoid actionPerformed(ActionEvent e){

String str = e.getActionCommand();

long g = Math.round(100*Math.random());

if (str.equals("Binary")){

squarePanel[new Long(g).intValue()].setBackground(Color.RED);

if(g == guess){

squarePanel[new Long(g).intValue()].setBackground(Color.RED);

}

else{

squarePanel[new Long(g).intValue()].setBackground(Color.WHITE);

}

}

}

I need some help on the timer class in java.I need to display a squarePanel to red..but after a few seconds later, i need to change it to blue after selecting another panel to show that it is selected before..After which, i will continue clicking the button until i select the correct squarePanel..any idea how to go about doing this?

[1513 byte] By [chankela] at [2007-10-2 2:07:22]
# 1

I do not fully understand the question, so forgive me if I answer the wrong question. Since it sounds like this happens only once, I would consider spawning off a lite weight thread that simply sleeps for the time needed and then wakes up and fires the necessary event.

(not tested)

Thread t = new MyTimerThread(TIME_TO_SLEEP, this) ;

t.start() ;

-

Class MyTimerThread extends Thread {

MyParentObject parent = null ;

long delay = 0L ;

public MyTimerThread (long delay, MyParentObject parent) {

this.parent = parent ;

this.delay = delay ;

}

public void run() {

try {

this.sleep (delay) ;

parent.doTheAction() ;

} catch (Exception e) {

//do nothing

}

}

}

kris.richardsa at 2007-7-15 19:48:48 > top of Java-index,Java Essentials,New To Java...
# 2
this 'memory-match' post sounds like it is what you're trying to do http://forum.java.sun.com/thread.jspa?threadID=633401
Michael_Dunna at 2007-7-15 19:48:48 > top of Java-index,Java Essentials,New To Java...