继续得到错误“(CLASS)不是抽象的,不会覆盖抽象方法”

时间:2014-10-03 18:54:35

标签: methods override abstract

当我尝试编译我的代码时,我得到两个相同的错误(标题上的那个)。我基本上只是从我的例子中复制而且我不明白为什么我会收到错误。我还在学习Java,所以我提前为我犯的任何错误道歉:P。这是代码:

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class ColorFactory extends JFrame {
 private final int winWidth=500;
 private final int winHeight=300;
 private JPanel topPanel;
 private JPanel bottomPanel;
 private JButton redButton;
 private JButton yellowButton;
 private JButton orangeButton;
 private JRadioButton greenRadio;
 private JRadioButton blueRadio;
 private JRadioButton cyanRadio;
 private JLabel message;

    public ColorFactory() {
     setTitle("Color Factory");
     setSize(winWidth, winHeight);
     setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
     setLayout(new BorderLayout());
     topPanel=new JPanel();
     bottomPanel=new JPanel();  
     message=new JLabel("Top buttons change the panel color and bottom radio buttons change the text color.");
     add(topPanel, BorderLayout.NORTH);
     add(bottomPanel, BorderLayout.SOUTH);
     add(message, BorderLayout.CENTER);
    }

    private void topButtons(){
     redButton=new JButton("Red");
     orangeButton=new JButton("Orange");
     yellowButton=new JButton("Yellow");
     setLayout(new FlowLayout());
     topPanel.setBackground(Color.WHITE);
     add(redButton);
     add(orangeButton);
     add(yellowButton);
     redButton.setBackground(Color.RED);
     yellowButton.setBackground(Color.YELLOW);
     orangeButton.setBackground(Color.ORANGE);
     redButton.addActionListener(new ButtonListener());
     orangeButton.addActionListener(new ButtonListener());
     yellowButton.addActionListener(new ButtonListener());
    }

    private void bottomButtons(){
      greenRadio=new JRadioButton("Green");
      blueRadio=new JRadioButton("Blue");
      cyanRadio=new JRadioButton("Cyan");
      setLayout(new FlowLayout());
      bottomPanel.setBackground(Color.WHITE);
      add(greenRadio);
      add(blueRadio);
      add(cyanRadio);
      greenRadio.setForeground(Color.GREEN);
      blueRadio.setForeground(Color.BLUE);
      cyanRadio.setForeground(Color.CYAN);
      greenRadio.addActionListener(new RadioButtonListener());
      blueRadio.addActionListener(new RadioButtonListener());
      cyanRadio.addActionListener(new RadioButtonListener());
    }

    private class ButtonListener implements ActionListener{
     public void actionPerfomed(ActionEvent e){
      String command=e.getActionCommand();
      if(command.equals("Red")){
       message.setBackground(Color.RED);
      }
      else if(command.equals("Yellow")){
       message.setBackground(Color.YELLOW);
      }
      else if(command.equals("Orange")){
       message.setBackground(Color.ORANGE); 
      }
     }
    }

    private class RadioButtonListener implements ActionListener{
     public void actionPerfomed(ActionEvent i){
      if(i.getSource()==greenRadio){
       message.setForeground(Color.GREEN);
      }
      else if(i.getSource()==blueRadio){
       message.setForeground(Color.BLUE);
      }
      else if(i.getSource()==cyanRadio){
       message.setForeground(Color.CYAN);   
      }
     }
    }

    public static void main(String[] args){
     new ColorFactory();
    }
}

这是我得到的错误:

error: ColorFactory.RadioButtonListener is not abstract and does not override abstract method actionPerformed(ActionEvent) in ActionListener
    private class RadioButtonListener implements ActionListener{
            ^

提前致谢!

1 个答案:

答案 0 :(得分:0)

方法名称应为actionPerformed而不是actionPerfomed。你错过了r

相关问题