已为我提供了执行保存操作的代码,但是当我将代码放入时,出现错误:
类saveAction的非法修饰符;仅允许摘要或最终摘要。
码:
protected void initialiseActions(){
// TODO: initalise your actions here
public class SaveAction extends AbstractAction{
public SaveAction(String text, ImageIcon icon, String desc, Integer mnemonic){
super(text, icon);
putValue(SHORT_DESCRIPTION, desc);
putValue(MNEMONIC_KEY, mnemonic);
}
public void actionPerformed(ActionEvent e){
// Just print out a message for now.
System.out.println("Save");
}
}
Action saveAction = new SaveAction("Save", new ImageIcon("img/save.png"), "Save the image",
KeyEvent.VK_S);
}
任何帮助,将不胜感激。谢谢
最佳答案
您不能声明public
本地类。删除public
标识符。
protected void initialiseActions(){
// TODO: initalise your actions here
class SaveAction extends AbstractAction{
public SaveAction(String text, ImageIcon icon, String desc, Integer mnemonic){
super(text, icon);
putValue(SHORT_DESCRIPTION, desc);
putValue(MNEMONIC_KEY, mnemonic);
}
public void actionPerformed(ActionEvent e){
// Just print out a message for now.
System.out.println("Save");
}
}
Action saveAction = new SaveAction("Save", new ImageIcon("img/save.png"), "Save the image",
KeyEvent.VK_S);
}
这在Java Language Specification中指定
如果本地类声明包含任何内容,则是编译时错误
公共,受保护或私有(第6.6节)的访问修饰符,或者
修饰符静态(第8.1.1节)。
关于java - Action 类的非法修饰符错误,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/19609664/