Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

TimeListener Error...

Hi everyone!

I'm developing a Reaction Tester program! i've been looking at some examples that others have made, to get an idea of whats involved and where to start...i've come across a good example, which is shown below...but it has an error! The line timer = new Timer(0, new TimeListener()); seems to not work...

I've talking to the computer science teacher at my school about it recently, and he suggested to use currentTimeMillis() method from the System class instead of TimeListener i think...would that be better? or am i very confused and those two have nothing in common? lol...

Sorry for asking all you guys here, i would have asked my teacher about it further, but we have just started school holidays over here...

Anyway, thanks for looking at this and hopefully helping me out!! :)

import java.applet.Applet;
import java.awt.*;
import java.util.Random;
import javax.swing.Timer;

public class ReactionTesterApplet extends Applet
{
TextField points;
Button button;
ReactionPanel circlePanel;
Timer timer;
int number;
Random numbers;
long startTime;
long endTime;

public ReactionTesterApplet()
{
points = new TextField("0");
button = new Button("Start");
circlePanel = new ReactionPanel();
timer = null;
number = 0;
numbers = new Random();
startTime = 0L;
endTime = 0L;
}

public void init()
{
setLayout(new GridLayout(1, 3));
add(points);
add(button);
add(circlePanel);

class TimeListener {}
timer = new Timer(0, new TimeListener());

class ButtonListener {}
button.addActionListener(new ButtonListener());
}
}

-Crawf
[1962 byte] By [crawf] at [2007-11-11 8:49:44]