简体   繁体   English

如何在 NetBeans IDE 中重命名我的主要 class?

[英]How can I rename my main class in the NetBeans IDE?

I am using NetBeans IDE and have created a new project.我正在使用 NetBeans IDE 并创建了一个新项目。 The new project includes a Main.java.新项目包括 Main.java。

Is it necessary to have it named Main.java, or can I rename the Main.java into another name?是否有必要将其命名为 Main.java,或者我可以将 Main.java 重命名为另一个名称吗? If so, how can I do this?如果是这样,我该怎么做? When I try to right-click Main.java, there is no rename option.当我尝试右键单击 Main.java 时,没有重命名选项。 I thought it was possible.我认为这是可能的。

There should be a menu item called应该有一个菜单项称为

Refactor --> Rename重构 --> 重命名

Link from NetBeans Wiki来自 NetBeans Wiki 的链接

Your name can be anything, as long as you have a你的名字可以是任何东西,只要你有一个

public static void main(String[] args) 

in it (This is only if you want this class to be the entry point when you run your application).在其中(仅当您希望此 class 成为运行应用程序时的入口点时)。

You can call the file <whatever you like>.java , but the name of the class in that file must match the new name you give to the file.您可以调用文件<whatever you like>.java ,但该文件中 class 的名称必须与您为该文件指定的新名称匹配。

So if you rename the file to MyCoolClass.java, you also have to change the class from public class Main to public class MyCoolClass . So if you rename the file to MyCoolClass.java, you also have to change the class from public class Main to public class MyCoolClass .

you can even have the simpler way,click on the file_name.java in the Projects panel,wait for a sec and click one more time (just as you rename any other folder/file).It will allow you to replace the new name and then it will popup a window asking whether you want to refactor or not...您甚至可以有更简单的方法,在“项目”面板中单击 file_name.java,等待一秒钟然后再单击一次(就像重命名任何其他文件夹/文件一样)。它将允许您替换新名称并然后它会弹出一个 window 询问您是否要重构...

you got to use the refractor, as it is the safest way to do such actions你必须使用折射镜,因为这是进行此类操作的最安全方法

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在Netbeans IDE中设置Main Class和main()方法 - Setting the Main Class and main() method in Netbeans IDE 如何在没有任何主类的情况下在netbeans IDE中运行Java applet - how to run Java applet in netbeans IDE without any main class 如何在NetBeans或其他Java IDE中按名称对类成员进行排序? - How can I sort class members by name in NetBeans, or another Java IDE? 在NetBeans IDE 6.1中,如何在GUI编辑器中获取自定义GUI组件的图标? - In NetBeans IDE 6.1 how can I get icons for my custom GUI components in the GUI editor? 如何设置Netbeans IDE以制作Java ME应用程序? - How can I setup my Netbeans IDE for making Java ME applications? 如何导出Java项目,使其无需IDE(netbeans)即可运行? - How do I export my java project so it can run without the help of the IDE (netbeans)? 如何使用库访问在netbeans中定义的bean类,可以在新项目的主要方法中使用 - how to access my bean class defined in netbeans using libraries can be used in main method of new project 如何使用我在主类中通过 Netbeans GUI 构建器创建的按钮? - How to use the Button I created via Netbeans GUI builder in my main class? 我怎样才能将数组称为主类? - How can I call my array to my main class? 在NetBeans IDE中找不到或加载主类消息 - Could not find or load main class message in netbeans IDE
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM