【问题标题】:Java applet error main method not foundJava小程序错误主方法未找到
【发布时间】:2016-06-10 14:23:42
【问题描述】:
//********************************************************************
//  Einstein.java       Author: Lewis/Loftus
//
//  Demonstrates a basic applet.
//********************************************************************

import javax.swing.JApplet;
import java.awt.*;

public class Einstein extends JApplet
{
   //-----------------------------------------------------------------
   //  Draws a quotation by Albert Einstein among some shapes.
   //-----------------------------------------------------------------
   public void paint (Graphics page)
   {
      page.drawRect (50, 50, 40, 40);    // square
      page.drawRect (60, 80, 225, 30);   // rectangle
      page.drawOval (75, 65, 20, 20);    // circle
      page.drawLine (35, 60, 100, 120);  // line

      page.drawString ("Out of clutter, find simplicity.", 110, 70);
      page.drawString ("-- Albert Einstein", 130, 100);
   }
}

错误:在 Einstein 类中找不到主方法,请将主方法定义为: 公共静态无效主要(字符串 [] 参数) 或者 JavaFX 应用程序类必须扩展 javafx.application.Application

我该如何解决这个问题?

【问题讨论】:

    标签: java


    【解决方案1】:

    我相信你正在使用 Eclipse 来运行这个程序。在那里你右键单击上面类中的任意位置,执行 Run As -> Java Applet 它将运行良好。

    下面是我在上面运行你的程序时得到的输出。

    【讨论】:

      【解决方案2】:

      如果您想像应用程序 java 一样运行它,则需要将条目 main 方法添加到您的类中:

        public static void main(String[] args) {
        ...
      

      但是,如果您想像 Applet 应用程序一样运行它,请使用 run java applet。

      【讨论】:

      • 我认为 Applet 不需要 main 方法。
      • 是的,但是如果他想像 java 应用程序一样尝试它,可以使用 main 方法 @Anil
      【解决方案3】:

      您需要一个 init(){} 函数。同样从我在网上看到的人们使用'Applet'而不是JApplet。我不建议从 chrome 开始制作 Java 小程序,不再支持 Java 和 Unity Web Player 等插件。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2017-08-02
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多