【发布时间】:2014-10-27 17:10:15
【问题描述】:
我使用 swing 组件和 JAPI 编写了一个简单的编辑器。当我运行程序时,它会显示一些错误。我将 JAPI jar 文件 (japi-lib-swing-action-0.3.0.jar) 添加到我的项目库中文件夹。我正在使用 NetBeans IDE。它显示以下错误“无法解析导入 net.sf.japi.swing.ActionMethod”。哪个 jar 文件包含该包。
这里是示例代码:
import org.jetbrains.annotations.Nullable;
import net.sf.japi.swing.ActionFactory;
import static net.sf.japi.swing.ActionFactory.getFactory;
import net.sf.japi.swing.ActionMethod;
import net.sf.japi.swing.ActionProvider;
public class Editor implements ActionProvider {
/** Action Factory. */
private static final ActionFactory ACTION_FACTORY = getFactory("net.sf.japi.examples.editor");
/** The supported editor action names and their corresponding kit action names. */
private static final Map<String, String> editorActionNames = new HashMap<String, String>();
static {
editorActionNames.put("editCut", DefaultEditorKit.cutAction);
editorActionNames.put("editCopy", DefaultEditorKit.copyAction);
};
/** Application frame. */
private final JFrame frame = new JFrame(ACTION_FACTORY.getString("frame.title"));
/** Editor component. */
private final JTextPane textPane = new JTextPane();
/** FileChooser for opening and saving files. */
private final JFileChooser fileChooser = new JFileChooser();
/** Currently opened file.
* Maybe <code>null</code> in case the current document was not already saved.
*/
private File file;
/** Create the Editor. */
public Editor() {
ACTION_FACTORY.addActionProvider(this);
frame.setJMenuBar(ACTION_FACTORY.createMenuBar(true, "editor", this));
frame.add(ACTION_FACTORY.createToolBar(this, "editor"), NORTH);
frame.add(new JScrollPane(textPane));
frame.pack();
frame.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
frame.setVisible(true);
}
/** {@inheritDoc} */
@Nullable public Action getAction(final String key) {
for (final Action action : textPane.getActions()) {
final String realKey = editorActionNames.get(key);
if (realKey != null && realKey.equals(action.getValue(Action.NAME))) {
ACTION_FACTORY.initAction(true, action, key);
return action;
}
}
return null;
}
/** Action method.
* @used
*/
@ActionMethod public void fileNew() {
textPane.setText("");
file = null;
}
【问题讨论】: