有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

找不到Java小程序错误主方法

//********************************************************************
//  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中找不到主方法,请将主方法定义为: 公共静态void main(字符串[]args) 或者JavaFX应用程序类必须扩展JavaFX。应用应用

我怎样才能解决这个问题


共 (3) 个答案

  1. # 1 楼答案

    您需要一个init(){}函数。从我在网上看到的情况来看,人们使用的是Applet而不是JApplet。我不建议让java小程序从chrome开始不再支持java和UnityWebPlayer之类的插件

  2. # 2 楼答案

    我相信您正在使用Eclipse来运行这个程序。在上面的类中,右键单击任意位置,执行运行方式->;Java小程序运行正常

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

    enter image description here

  3. # 3 楼答案

    如果要像java应用程序一样运行,需要将entrymain方法添加到类中:

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

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