一个最小的 Java 程序应该是什么样子的?
我编写了以下代码:
import java.awt.*;
import java.awt.event.*;
class Party {
public void buildInvite() {
Frame f = new Frame();
Label l = new Label("Party at Tim's");
Button b = new Button("You bet");
Button c = new Button("Shoot me");
Panel p = new Panel();
p.add(l);
} //more code here...
}
我不断收到以下错误: Exception in thread "main" java.lang.NoSuchMethodError: main
我尝试添加一个额外的 main (String[] args )
到代码中,但我仍然遇到相同的错误。
我还应该在代码中添加什么以及它应该放在布局中的什么位置?
I wrote the following code:
import java.awt.*;
import java.awt.event.*;
class Party {
public void buildInvite() {
Frame f = new Frame();
Label l = new Label("Party at Tim's");
Button b = new Button("You bet");
Button c = new Button("Shoot me");
Panel p = new Panel();
p.add(l);
} //more code here...
}
I keep getting the following error: Exception in thread "main" java.lang.NoSuchMethodError: main
I've tried to add an additional main (String[] args)
to the code but I still get the same errors.
What additionally I should put in the code and where in the layout should it go?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
确保您的
main
方法如下所示:Make sure your
main
method looks like this:Java 和 Swing 初学者应该查看 Oracle 教程。这是他们的 Swing Hello World 程序:
Beginners with Java and Swing should check out the Oracle tutorial. Here's their Swing Hello World program: