Java 为什么我得到的显示不是抽象的,并且不会覆盖显示中的抽象方法actionPerformed()?
我一直在遵循一些关于制作文字处理器的教程,并遵循了每一步,但当我遇到以下错误时,我被卡住了: Display不是抽象的,也不会覆盖Display中的抽象方法actionPerformed() 我用于显示的代码:Java 为什么我得到的显示不是抽象的,并且不会覆盖显示中的抽象方法actionPerformed()?,java,jakarta-ee,Java,Jakarta Ee,我一直在遵循一些关于制作文字处理器的教程,并遵循了每一步,但当我遇到以下错误时,我被卡住了: Display不是抽象的,也不会覆盖Display中的抽象方法actionPerformed() 我用于显示的代码: import java.awt.Color; import java.awt.Dimension; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JB
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);
}
}
Java中的标识符区分大小写。 在您的代码中,有一个名为
actionperformed
的方法,但是actionperformed
应该被实现
如果我们的方法重写了另一个方法或实现了抽象方法声明(注意:接口中的所有方法声明都是隐式抽象的),那么使用注释也是一种很好的做法。这允许编译器执行额外的检查方法是否真的重写了另一个,如果它没有重写,则会产生错误。您的类实现了接口
ActionListener
,但没有实现接口的约定要求
您必须实现actionPerformed
方法,如ActionListener
界面所述
有关更多详细信息,请参见能否提及@Override annotation;)@当然。好主意。如果你认为我应该说得更清楚,我感谢你的帮助:)不,我认为你做得很好;)