This is a very simple timer and I cant seem to get it to work
I have tried this () runs but does nothing:
// The "Timer" class.
import java.applet.*;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class Timer extends Applet implements ActionListener
{
// Place instance variables here
Timer timer;
int num = 0;
public void init ()
{
timer = new Timer ();
timer.start ();
// Place the body of the initialization method here
} // init method
public void paint (Graphics g)
{
g.drawString ("Number: " + num, 100,100);
// Place the body of the drawing method here
} // paint method
public void actionPerformed(ActionEvent e) {
//If still loading, can't animate.
num += 1;
}
} // Timer class
and this (gives me an error when I am making the timer):
// The "Timer" class.
import java.applet.*;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class Timer extends Applet implements ActionListener
{
// Place instance variables here
Timer timer;
int num = 0;
public void init ()
{
timer = new Timer (1000, this);
timer.start ();
// Place the body of the initialization method here
} // init method
public void paint (Graphics g)
{
g.drawString ("Number: " + num, 100,100);
// Place the body of the drawing method here
} // paint method
public void actionPerformed(ActionEvent e) {
//If still loading, can't animate.
num += 1;
}
} // Timer class
Thanks for any help.