如何删除 NetBeans 中的 actionPerformed 方法

发布于 2024-12-06 13:20:04 字数 499 浏览 1 评论 0原文

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

刘备忘录 2024-12-13 13:20:04

转到 JButton 属性,选择“Events”、actionPerformed,然后从相邻的组合框中选择“none”。您的源代码已清理!

Netbeans Properties

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!

Netbeans Properties

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:

enter image description here

铃予 2024-12-13 13:20:04

如果注册操作的按钮不再在表单中(在我用以前的备份手动替换 .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.

深府石板幽径 2024-12-13 13:20:04

在最新版本的 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.

猫瑾少女 2024-12-13 13:20:04

识别您的 .java 文件,然后关闭 Netbeans 并直接从文本编辑器编辑您的文件。

Identify your .java file, then close Netbeans and edit your file directly from a text editor.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文