I get this error:
LBMPG.java:51: LBMPG.CalcButtonListener is not abstract and does not override abstract method actionPerformed(java.awt.event.ActionEvent) in java.awt.event.ActionListener
private class CalcButtonListener implements ActionListener
^
This is my code:
import javax.swing.*; import java.awt.event.*; public class LBMPG extends JFrame { private JPanel panel; private JLabel gallonLabel; private JLabel milesLabel; private JTextField gallonsTextField; private JTextField milesTextField; private JButton calcButton; private final int WINDOW_WIDTH = 400; private final int WINDOW_HEIGHT = 100; public LBMPG() { setTitle("Miles per Gallon"); setSize(WINDOW_WIDTH, WINDOW_HEIGHT); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); buildPanel(); add(panel); setVisible(true); } private void buildPanel() { gallonLabel = new JLabel("Enter the amount of gallons your tank holds:"); gallonsTextField = new JTextField(2); milesLabel = new JLabel("Enter the amount of miles you can go on a full tank:"); milesTextField = new JTextField(3); calcButton = new JButton("Calculate MPG"); calcButton.addActionListener(new CalcButtonListener()); panel = new JPanel(); panel.add(gallonLabel); panel.add(gallonsTextField); panel.add(milesLabel); panel.add(milesTextField); panel.add(calcButton); } private class CalcButtonListener implements ActionListener { public void actionPerfmored(ActionEvent e) { String input; double mpg; double gallons; double miles; input = gallonsTextField.getText(); gallons = Double.parseDouble(input); input = milesTextField.getText(); miles = Double.parseDouble(input); mpg = miles / gallons; JOptionPane.showMessageDialog(null, "Your car gets approximately " + mpg + " miles per gallon."); } } }
I don't understand it. I've looked up things to fix it, but they didn't work. It's also weird because I pretty much followed another code to get the basic outline, and then changed everything to fit this scenario.