1
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();
    }
  }
}

我不断遇到的这两个错误不知道我在做什么错。我从另外两个框架中调用了这个框架,这两个框架都以与这个相同的格式使用了 ActionListener。如果有人有任何建议,请帮助。

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)
4

2 回答 2

1

公共无效actionPreformed(ActionEvent e)

形成。不是预先形成的。

始终使用@Override。

@Override
public void actionPerformed(ActionEvent e){
于 2012-06-20T12:09:54.577 回答
0

第 140 行:您的方法名称错误。它不是

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

但它的

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

actionPerformed

于 2012-06-20T12:21:12.317 回答