I am having a problem get my program to compile.

ERROR
Stopwatch.java:35: cannot find symbol
symbol : method start()
location: class Timer
timer.start();
^
Stopwatch.java:44: cannot find symbol
symbol : method stop()
location: class Timer
timer.stop();
^
Stopwatch.java:52: cannot find symbol
symbol : constructor Timer(int,Stopwatch)
location: class Timer
timer = new Timer(1000, this);
^
3 errors

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;

public class Stopwatch extends JApplet implements ActionListener 
{
	//instance variables
	private JLabel countLabel;
	private JButton start;
	private JButton stop;
	private Timer timer;
	private int count= 0;

	public void init()
	{

		//set layout 
		setLayout(new BorderLayout());
	
		countLabel =  new JLabel("");
		countLabel.setHorizontalAlignment(JLabel.CENTER);
		countLabel.setForeground(Color.RED);
		countLabel.setFont(new Font("Times new Roman", Font.BOLD, 60));
		add(countLabel, BorderLayout.CENTER);
		
		JPanel panel = new JPanel();
		
		start = new JButton ("Start");
		start.addActionListener(new ActionListener()
        {
            public void actionPerformed(ActionEvent e)
            {
            	count = 1;
                timer.start();
            }
        }); 
		stop = new JButton ("Stop");
		stop.addActionListener(new ActionListener()
        {
            public void actionPerformed(ActionEvent e)
            {
            	
                timer.stop();
            }
        }); 
		
		panel.add(start);
		panel.add(stop);
		add(panel, BorderLayout.NORTH);
		//getting the new timer
		timer = new Timer(1000, this);
		
	} // end method init     
    //
	public void paint(Graphics g) {
		
		countLabel.setText(""+ count);  
		count++;
	}
	//method for handling the actions
	public void actionPerformed(ActionEvent e) {
		repaint();	
	 }

	    
} // end class

This looks OK to me. Only thing I can think of is that it may be using the java.util.Timer not the javax.swing.Timer (although with your include statements that shouldn't happen?). If you're still stuck it may be worth just trying making that explicit by changing line 12 to

private javax.swing.Timer timer;

ps You don't have classes you wrote yourself called Timer hanging around do you?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.