I keep getting an error with the "ButtonListener." I don't know what it is that's causing it, but help would be appreciated.

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class MovingCarPanel extends JPanel
  private int delay = 2;
  private Car car;
  private Timer timer;
  private JButton accelerate, decelerate;
  private JPanel buttonPanel;

  int x, y;
  int moveX;

  public MovingCarPanel()
    accelerate = new JButton ("Accelerate");
    decelerate = new JButton ("Decelerate");

    ButtonListener listener = new ButtonListener();

    buttonPanel = new JPanel();
    buttonPanel.setPreferredSize(new Dimension(200, 40));
    //buttonPanel.setBackground (Color.blue);
    buttonPanel.add (accelerate);
    buttonPanel.add (decelerate);

    add (buttonPanel);

    timer = new Timer(delay, null);
    timer.addActionListener(new SideCarListener());
    car = new Car(50, 90, 90, 15);

    setPreferredSize(new Dimension(700, 500));
    addMouseListener(new MouseCarListener());

    x = 50;
    y = 300;
    moveX = 1;

  public void paintComponent (Graphics page)

  private class MouseCarListener implements MouseListener
    public void mousePressed(MouseEvent event)
        moveX = -1*moveX;
    public void mouseClicked(MouseEvent event){}
    public void mouseReleased(MouseEvent event){}
    public void mouseEntered(MouseEvent event){}
    public void mouseExited(MouseEvent event){}

  private class SideCarListener implements ActionListener
    public void actionPerformed(ActionEvent event)
      if(x == 700 && moveX > 0)
        x = -90;
      else if(x < -90 && moveX < 0)
        x = 700;



Thank you!

2 errors found:
[line: 24]
Error: cannot find symbol
symbol: class ButtonListener
location: class MovingCarPanel
[line: 24]
Error: cannot find symbol
symbol: class ButtonListener
location: class MovingCarPanel

perhaps you are using the wrong name? because i cant find a class called ButtonListener?

Edited 4 Years Ago by DavidKroukamp

This question has already been answered. Start a new discussion instead.