简体   繁体   English

为什么我得到的Display不是抽象的并且没有覆盖Display中的抽象方法actionPerformed()?

[英]Why am I getting the Display is not abstract and does not override abstract method actionPerformed() in Display?

I've been following some tutorials on making word processors and have followed every step however I got stuck when I ran into this error: 我一直在关注一些有关文字处理程序的教程,并且按照每个步骤进行操作,但是遇到此错误时我陷入了困境:

Display is not abstract and does not orverride abstract method actionPerformed() in Display Display不是抽象的,并且不会覆盖Display中的抽象方法actionPerformed()

the code I use for Display: 我用于Display的代码:

import java.awt.Color;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JSlider;
import javax.swing.JTextPane;


public class Display extends JPanel implements ActionListener {
    private JTextPane textArea;
    private JButton saveButton;
    private JComboBox colorCombo;
    private JComboBox fontCombo;
    private JLabel processorLabel;
    private JSlider fontSize;

    //addAction Listener methods.
public void actionperformed(ActionEvent e){

}


// create arrays.
    String[] colorItems = {"red", "Blue", "Green", "Purple", "Orange", "Black"};
    String[] fontItems = {"Monospaced", "Serif", "San Serif"};
//constructor.
    public Display(){
        init(); // Display calls for init.
    }
    public void init(){ // where buttons and labels coding go.
     //construct components.
       textArea = new JTextPane();
       saveButton = new JButton("save");
       colorCombo = new JComboBox(colorItems);
       fontCombo = new JComboBox(fontItems);
       processorLabel = new JLabel("Mo's W.P");
       fontSize = new JSlider(10, 30);


       //Slider work.
       fontSize.setOrientation(JSlider.HORIZONTAL);
       fontSize.setMinorTickSpacing(1);
       fontSize.setMajorTickSpacing(5);
       fontSize.setPaintTicks(true); //displays the text.
       fontSize.setPaintLabels(true); //displays paint pop ups

       // Make text area presentable.
       textArea.setBackground(Color.LIGHT_GRAY);
       //textArea.setForeground(color);

       //adjust size and layout.
       setPreferredSize(new Dimension(817, 473));
       setLayout(null);

       //add components.
       add(textArea);
       add(saveButton);
       add(colorCombo);
       add(fontCombo);
       add(processorLabel);
       add(fontSize);

       textArea.setBounds(10, 10, 650, 450);
       saveButton.setBounds(670, 315, 140, 35);
       colorCombo.setBounds(670, 205, 140, 53);
       fontCombo.setBounds(670, 150, 140, 35);
       processorLabel.setBounds(670, 20, 140, 35);
       fontSize.setBounds(670, 95, 140, 40);

       //add action listeners. 
       saveButton.addActionListener(this);
       colorCombo.addActionListener(this);
       fontCombo.addActionListener(this);

    }


}

The identifiers in Java are case-sensitive. Java中的标识符区分大小写。 In your code there is a method named actionperformed , but actionPerformed is expected to be implemented. 您的代码中有一个名为actionperformed的方法,但是actionPerformed有望实现。

It's also good practice to use @Override annotation if our method overrides another method or implements abstract method declaration (note: all method declarations in interfaces are implicit abstract). 如果我们的方法重写另一个方法或实现抽象方法声明(请注意:接口中的所有方法声明都是隐式抽象),则使用@Override注解也是一种好习惯。 This allows compiler to perform additional check if method really overrides another and produces error if it does not. 如果方法确实覆盖另一个方法,则编译器可以执行其他检查,否则将产生错误。

Your class implements the interface ActionListener , but doesn't implement the contractual requirements of the interface 您的类实现了ActionListener接口,但未实现该接口的合同要求

You must implement the actionPerformed method as described by the ActionListener interface 您必须实现ActionListener接口所描述的actionPerformed方法

See How to write a ActionListener for more details 有关更多详细信息,请参见如何编写ActionListener

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 SearchEventListener 不是抽象的,不会覆盖抽象方法 actionPerformed - SearchEventListener is not abstract and does not override abstract method actionPerformed Select不是抽象的,并且不会覆盖ActionListener中的抽象方法actionPerformed(ActionEvent) - Select is not abstract and does not override abstract method actionPerformed(ActionEvent) in ActionListener 错误:LoginController 不是抽象的并且不会覆盖抽象方法 actionPerformed - Error:LoginController is not abstract and does not override abstract method actionPerformed ExitButtonHandler不是抽象的,并且不会重写ActionListener中的抽象方法actionPerformed(ActionEvent) - ExitButtonHandler is not abstract and does not override abstract method actionPerformed(ActionEvent) in ActionListener 得到错误:BodyMassApplet不是抽象的,并且不会覆盖抽象方法actionPerformed(ActionEvent) - Get error: BodyMassApplet is not abstract and does not override abstract method actionPerformed(ActionEvent) 类不是抽象的,并且不覆盖抽象方法actionPerformed(ActionEvent) - Class is not abstract and does not override abstract method actionPerformed(ActionEvent) AListener不是抽象的,并且不会覆盖ActionListener中的抽象方法actionPerformed(ActionEvent) - AListener is not abstract and does not override abstract method actionPerformed(ActionEvent) in ActionListener 类不是抽象的,并且不会重写ActionListener中的抽象方法actionPerformed(ActionEvent) - Class is not abstract and does not override abstract method actionPerformed(ActionEvent) in ActionListener ActionListener不是抽象的,并且不会覆盖抽象方法,但是我有一个actionPerformed,这是怎么回事? - ActionListener is not abstract and does not override abstract method, but i have a actionPerformed, what is wrong? 为什么我使用这种抽象方法会出错? - Why am I getting an error with this abstract method?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM