Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Action Listener Error

  1. #1
    Junior Member
    Join Date
    Jun 2011
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Action Listener Error

    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.


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,318
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: Action Listener Error

    java is very sensitive when it comes to spelling. In other words, actionPerfmored != actionPerformed
    The @Override annotation helps track these problems, and will indicate that a method does not override or implement a super class method or interface.

Similar Threads

  1. Action Listener
    By Suzanne in forum What's Wrong With My Code?
    Replies: 7
    Last Post: May 29th, 2010, 10:50 AM
  2. Beginner Help (Action Listener)
    By gradstudent in forum AWT / Java Swing
    Replies: 2
    Last Post: April 30th, 2010, 10:26 AM
  3. Action Listener
    By kray66 in forum AWT / Java Swing
    Replies: 2
    Last Post: April 19th, 2010, 03:26 PM
  4. Problem with Action Listener
    By JonoScho in forum AWT / Java Swing
    Replies: 4
    Last Post: March 19th, 2010, 01:03 AM
  5. Need Help Action Listener....
    By vhizent23 in forum AWT / Java Swing
    Replies: 2
    Last Post: October 9th, 2009, 01:46 PM