简体   繁体   English

运行旧的Java程序

[英]Running old Java Programs

a few years back in college I wrote TONS of simple little java programs... I haven't used them in a while and I would like to go back and revist them. 几年前,我写了很多简单的Java小程序……我已经有一段时间没有用过了,我想回去修改它们。 I believe I used Netbeans as my IDE (but i also could have used Eclipse... cant remember).. 我相信我将Netbeans用作我的IDE(但是我也可以使用Eclipse。。。

anyways long story short.... I cant remember how to compile them and I cant open these as projects in any of my IDEs.... 总之长话短说...。我不记得如何编译它们,也无法在我的任何IDE中将它们作为项目打开。

I've tried using javac and then java to run a few in the command line, however one specifically will not run and gives me this error: 我试过使用javac ,然后尝试在命令行中运行java ,但是专门无法运行,并给了我这个错误:

Exception in thread "main" java.lang.NoSuchMethodError: main

I know this is because I don't have a public static void main method in this program. 我知道这是因为我在此程序中没有public static void main方法。 I can't remember why I don't.... but here's in theory how it should work.... I have 3 program files: 我不记得为什么我不...。但是从理论上讲这应该如何工作。...我有3个程序文件:

  • race.java race.java
  • bicyclePanel.java bicyclePanel.java
  • controlPanel.java controlPanel.java

race extends JApplet and has a method public void init() .... which creates an instance of controlPanel class.... controlPanel class creates an instance of bicyclePanel and so on and so forth.... race扩展了JApplet并有一个方法public void init() ....它创建了bicyclePanel类的实例。... controlPanel类创建了bicyclePanel的实例,依此类推。

my question is.. am I supposed to have a main method? 我的问题是..我应该有一种main方法吗? How can I rebuild this into an IDE and run? 如何将其重建到IDE中并运行? It's been so many years I cant remember all the in's & outs of java :( 这么多年了,我不记得java的所有来龙去脉:(

Fire up NetBeans or Eclipse and Import the Projects with existing sources. 启动NetBeans或Eclipse,并使用现有源导入项目。 It will do most of the stuff. 它将完成大部分工作。 You may have to adjust the broken references. 您可能需要调整断开的引用。

Yes, you are supposed to have the main method if you plan on running it as a standalone Java application. 是的,如果计划将其作为独立的Java应用程序运行,则应该使用main方法。 In Eclipse you can use the Applet runner to run your applets directy as well. 在Eclipse中,您也可以使用Applet运行程序直接运行您的Applet。 It's Run As -> Java Applet. 运行方式-> Java Applet。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM