Why do I keep getting an [line: 75] Error:must implement the inherited abstract method java.awt.event.ActionListener?

不羁岁月 提交于 2019-12-11 06:42:31

问题


import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionListener;
import java.awt.event.*;
import java.io.*;
import java.util.*;

public class WetBulbByLocationFrame2 extends JFrame
{
  public JLabel countryLabel = new JLabel("Country");
  public JPanel countryPanel = new JPanel();
  public JComboBox countryBox;
  public String [] northAmericanCountries = {"Antigua", "Aruba", "Bahamas", "Barbados", "Bermuda", "Canada", "Costa Rica", "Cuba", "Dominican Republic", "Grenada", "Guadalupe", "Honduras", "Jamaica", "Martinique", "Panama", "Puerto Rico", "Saint Lucia", "Trinidad and Tobago", "United States of America"};
  public String [] africanCountries = {"Algeria", "Benin", "Botswana", "Burkina Faso", "Cape Verde", "Chad", "Congo", "Cote d'Ivoire", "Egypt", "Gambia", "Kenya", "Libya", "Madagascar", "Mali", "Mauritania", "Mauritania", "Morocco", "Mozambique", "Namibia", "Niger", "Reunion", "Saint Helena", "Senegal", "Seychelles", "South Africa", "Spain", "Tanzania", "Togo", "Tunisia", "United Kingdom", "Zimbabwe"}; 
  public String [] asianCountries = {"Bahrain", "China", "India", "Iran", "Japan", "Kazakhstan", "Korea, North", "Korea, South", "Kuwait", "Kyrgyzstan", "Macau", "Mongolia", "Oman", "Pakistan", "Qatar", "Russian Federation", "Saudi Arabia", "Taiwan", "Tajikistan", "Thailand", "Turkmenistan", "United Arab Emirates", "Uzbekistan", "Vietnam"};
  public String [] europeanCountries = {"Armenia", "Austria", "Azerbaijan", "Belarus", "Belgium", "Bosnia and Herzegovina", "Bulgaria", "Croatia", "Cyprus", "Czech Republic", "Denmark", "Estonia", "Faroe Islands", "Finland", "France", "Georgia", "Germany", "Gibraltar", "Greece", "Greenland", "Hungary", "Iceland", "Ireland", "Israel", "Italy", "Jordan", "Kazakhstan", "Latvia", "Lebanon", "Liechtenstein", "Lithuania", "Luxembourg", "Macedonia", "Malta", "Moldova", "Netherlands", "Norway", "Poland", "Portugal", "Romania", "Russian Federation", "Serbia and Montenegro", "Slovakia","Slovenia", "Spain", "Sweden", "Switzerland", "Syrian Arab Republic", "Turkey", "Ukraine", "United Kingdom"};
  public String [] southAmericanCountries = {"Argentina", "Bolivia", "Brazil", "Chile", "Columbia", "Ecuador", "Falkland Islands", "French Guinea", "Paraguay", "Peri", "Suriname", "Uruguay", "Venezuela"};
  public String [] southPacificCountries = {"Australia", "Brunei Darussalam", "Cook Island", "Fiji", "French Polynesia", "Guam", "Indonesia", "Kiribati", "Malaysia", "Marshall Island", "Micronesia", "New Caledonia", "New Zealand", "Northen Mariana Islands", "Palau", "Philippines", "Samoa", "Singapore", "Solomon Island", "Tonga", "Tuvalu", "United States of America", "Vanuatu", "Wallis and Futuna Islands"};
  public JButton nextButton = new JButton("Next");
  public JPanel buttonPanel = new JPanel();
  public String country;
  public String continentGIVEN;

  public WetBulbByLocationFrame2(String continent)
  {
    super("Select Country");
    Toolkit toolkit = Toolkit.getDefaultToolkit();
    Dimension dimensions = toolkit.getScreenSize();
    int x = (dimensions.width - 315)/2; 
    int y = (dimensions.height - 250)/2;
    setBounds(x, y, 315, 250); 
    setVisible(true);
    setResizable(false);
    setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    continentGIVEN = continent;

    nextButton.addActionListener(new ButtonListener2());

    if (continent.equals("North America and Central America"))
    {
      countryBox = new JComboBox(northAmericanCountries);
    }
    else if(continent.equals("Africa"))
    {
      countryBox = new JComboBox(africanCountries);
    }
    else if(continent.equals("Asia"))
    {
      countryBox = new JComboBox(asianCountries);
    }
    else if(continent.equals("Europe"))
    {
      countryBox = new JComboBox(europeanCountries);
    }
    else if(continent.equals("South America"))
    {
      countryBox = new JComboBox(southAmericanCountries);
    }
    else if(continent.equals("South Pacific"))
    {
      countryBox = new JComboBox(southPacificCountries);
    }

    countryBox.addActionListener(new ComboBoxListener1());

    countryPanel.add(countryLabel);
    countryPanel.add(countryBox);

    add(countryPanel, BorderLayout.CENTER);

    buttonPanel.add(nextButton);

    add(buttonPanel, BorderLayout.SOUTH);   
  }
  private class ButtonListener2 implements ActionListener
  {
    public void actionPreformed(ActionEvent e)
    {
      if ((country.equals("United States of America")) || (country.equals("Canada")))
      {
        // Go into a specific new frame class to deal with the states and provinces
      }
      else if (country.equals("Russian Federation"))
      {
        //Go into new frame class with the large number of Russian Cities
      }
      else if (country.equals("China"))
      {
        //Go into new frame class with the large number of Chinese Cities
      }
      else if (country.equals("Spain"))
      {
        //Go into new frame class with the Spainish Cities
      }
      else if (country.equals("United Kingdom"))
      {
        //Go into new frame class with the large number of United Kingdom Cities
      }
      else if (continentGIVEN.equals("Africa"))
      {
        if ((!country.equals("United Kingdom")) || (!country.equals("Spain")))
        {
          //Go into new frame class with all African cities minus the UK locations
        }
      }
      else if (continentGIVEN.equals("Asia"))
      {
        if ((!country.equals("Russian Federation")) || (!country.equals("China")))
        {
          //Go into new frame class with all other Asian Cities
        }
      }
      else if (continentGIVEN.equals("Europe"))
      {
        if ((!country.equals("Russian Federation")) || (!country.equals("UnitedKingdom")) ||(!country.equals("Spain")))
        {
          //Go into new frame class with all other European Cities
        }
      }
      else if (continentGIVEN.equals("North America and Central America"))
      {
        if ((!country.equals("United States of America")) || (!country.equals("Canada")))
        {
          //Go into new frame class with all Central American Cities
        }
      }
      else if (continentGIVEN.equals("South America"))
      {
        //Go into new Frame class with only South American cities
      }
      else if (continentGIVEN.equals("South Pacific"))
      {
        if (!country.equals("United States of America"))
        {
          //Go into new frame class with all other South Pacific Cities
        }
      }
    }
  }
  private class ComboBoxListener1 implements ActionListener
  {
    public void actionPreformed(ActionEvent e)
    {
      country = (String)countryBox.getSelectedItem();
    }
  }
}

These two errors I keep getting don't know what I'm doing wrong. I have this frame being called from two other frames which both have ActionListener being used in the same formats as this one. If anyone has any suggestions please help.

File: C:\Documents and Settings\jcoppola\Desktop\Cooling Tower Program\WetBulbByLocationFrame2.java  [line: 75]
Error: The type WetBulbByLocationFrame2.ButtonListener2 must implement the inherited abstract method java.awt.event.ActionListener.actionPerformed(java.awt.event.ActionEvent)
File: C:\Documents and Settings\jcoppola\Desktop\Cooling Tower Program\WetBulbByLocationFrame2.java  [line: 140]
Error: The type WetBulbByLocationFrame2.ComboBoxListener1 must implement the inherited abstract method java.awt.event.ActionListener.actionPerformed(java.awt.event.ActionEvent)

回答1:


public void actionPreformed(ActionEvent e)

performed. Not preformed.

Always use @Override.

@Override
public void actionPerformed(ActionEvent e){



回答2:


line no 140: your method name is wrong. its not

     public void actionPreformed(ActionEvent e)
      {
         country = (String)countryBox.getSelectedItem();
      }

but its

   public void actionPerformed(ActionEvent e)
    {
        country = (String)countryBox.getSelectedItem();
     }

see actionPerformed



来源:https://stackoverflow.com/questions/11119191/why-do-i-keep-getting-an-line-75-errormust-implement-the-inherited-abstract

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!