快速业务通道

NetBeans:您的第一个插件 - 编程入门网

作者 佚名技术 来源 NET编程 浏览 发布时间 2012-06-16
ogs API 和 Utilities API。

NetBeans:您的第一个插件(5)

时间:2011-07-20 Silveira

现在我们第一次整理代码。

在 HelloAction.java 文件中, HelloAction 类扩展了 CallableSystemAction(它是一个抽象类)。在 performAction() 方法中只 有:

//TODO implement action body

我们将重新编写 performAction 方法:

public void performAction() {   String msg = "Hello NetBeans World!";   int msgType = NotifyDescriptor.INFORMATION_MESSAGE;   NotifyDescriptor d = new NotifyDescriptor.Message(msg, msgType);   DialogDisplayer.getDefault().notify(d); }

您将看到一些警告(不能找到符号)。修复所导入的内容(Ctrl+Shift+I)。要测试您的模块,请再次执行以下操作:NetBeans:您的第一个插件 - 编程入门网HelloYou → Install/Reload in Target Platform。NetBeans 的新 实例打开后,您将再次看到笑脸按钮。当您单击笑脸按钮时,NetBeans 将显示一段对话。

NetBeans:您的第一个插件 - 编程入门网

图 17. Hello NetBeans World。

让我们再做一些其他工作。我们使用 NotifyDescriptor.InputLine 与用户交谈。我们需要创建一个输入对话行,获取用户名称(如果单击 Ok 按钮),然后发送一条消息给他。

public void performAction() {    NotifyDescriptor.InputLine question;    question = new NotifyDescriptor.InputLine("Name:",      "What''s your name?",      NotifyDescriptor.OK_CANCEL_OPTION,      NotifyDescriptor.QUESTION_MESSAGE);    if (DialogDisplayer.getDefault().notify(question) == NotifyDescriptor.OK_OPTION) {      String msg = "Hello "+question.getInputText()+"!";      int msgType = NotifyDescriptor.INFORMATION_MESSAGE;      NotifyDescriptor d = new NotifyDescriptor.Message(msg, msgType);      DialogDisplayer.getDefault().notify(d);    } }

再次执行NetBeans:您的第一个插件 - 编程入门网HelloYou → Install/Reload in Target Platform 操作。

在 NetBeans 实例打开之后,单击我们设计的微笑按钮。

NetBeans:您的第一个插件 - 编程入门网

NetBeans:您的第一个插件 - 编程入门网

我们已经完成了 NetBeans 插件的创建!

凌众科技专业提供服务器租用、服务器托管、企业邮局、虚拟主机等服务,公司网站:http://www.lingzhong.cn 为了给广大客户了解更多的技术信息,本技术文章收集来源于网络,凌众科技尊重文章作者的版权,如果有涉及你的版权有必要删除你的文章,请和我们联系。以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢!

分享到: 更多

Copyright ©1999-2011 厦门凌众科技有限公司 厦门优通互联科技开发有限公司 All rights reserved

地址(ADD):厦门软件园二期望海路63号701E(东南融通旁) 邮编(ZIP):361008

电话:0592-5908028 传真:0592-5908039 咨询信箱:web@lingzhong.cn 咨询OICQ:173723134

《中华人民共和国增值电信业务经营许可证》闽B2-20100024  ICP备案:闽ICP备05037997号