如何删除 NetBeans 中的 actionPerformed 方法
当 JButton
添加到内容窗格时,我们可以通过双击按钮或右键单击 ->Event->Action->actionPerformed 来设置操作。比方说,我们将某些内容设置为发生。然后我们需要删除该功能。通过删除我们在该按钮的actionPerformed中编写的代码可以轻松完成此操作。但问题是,该按钮的 actionPerformed 方法仍然存在,尽管它不再使用且不再需要。
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
//no function here.. but this code is still remaining. need to remove this code part as well
}
如何去除?我以 JButton 为例。其他组件的动作方法都是这样。
When a JButton
is added to a content pane, we can set an action by double clicking the button or Right click->Event->Action->actionPerformed.Let say, we set somthing to happen. Then we need to remove that function.It can be done easily by deleting the code we wrote in that buttton's actionPerformed. But the problem is, that button's actionPerformed method is still there even though it is not used any more and not needed.
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
//no function here.. but this code is still remaining. need to remove this code part as well
}
How can it be removed? I got the JButton for an example. Other components'action methods are like this.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
转到 JButton 属性,选择“Events”、actionPerformed,然后从相邻的组合框中选择“none”。您的源代码已清理!
Netbeans 的最新版本(例如 7.3)不提供“none”选项,但允许您删除 actionPerformed通过删除方法名称或按 1、2 和 3 按钮来调用方法:
Go to your JButton properties, Choose "Events", actionPerformed and choose "none" from the adjacent combobox. Your source code is cleaned!
Recent versions of Netbeans like 7.3, do not offer "none" as an option, but allow you to delete the actionPerformed method by deleting the name of the method or by pressing 1, 2 and 3 buttons:
如果注册操作的按钮不再在表单中(在我用以前的备份手动替换 .form 文件后,我就发生了这种情况),那么您将无法执行 Costis Aivalis 的解决方案。在这种情况下,您可以使用另一个文本编辑器打开 .java 文件并删除其中的事件处理程序。
If the button that the action was registered to is no longer in the form (this happened to me after I manually replaced the .form file with a previous backup) then you wont be able to do Costis Aivalis's solution. In this case you can open the .java file with another text editor and delete the event handler there.
在最新版本的 netbeans 中,单击组合框右侧带有 3 个句点 [...] 的按钮,将显示一个列出处理程序的新控件。选择要删除的内容,然后按[删除]按钮。
In the latest version of netbeans click the button with the 3 periods [...] just to the right ov the combo box and a new control listing the handlers is displayed. Select the one to remove and press the [Remove] button.
识别您的 .java 文件,然后关闭 Netbeans 并直接从文本编辑器编辑您的文件。
Identify your .java file, then close Netbeans and edit your file directly from a text editor.