首页 文章

找不到Java applet错误主要方法

提问于
浏览
0
//********************************************************************
//  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类中找不到主方法,请将main方法定义为:public static void main(String [] args)或JavaFX应用程序类必须扩展javafx.application.Application

我怎样才能解决这个问题?

3 回答

  • 0

    你需要一个init(){}函数 . 同样从我在网上看到的人们使用'Applet'而不是JApplet . 我不建议制作java applet,因为chrome不再支持Java和Unity Web Player等插件 .

  • 0

    我相信你正在使用Eclipse来运行这个程序 . 你可以在上面的课程中点击任意位置,执行 Run As -> Java Applet 并且运行正常 .

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

    enter image description here

  • 0

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

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

    但是如果你想像Applet应用程序那样运行它,请使用run java applet .

相关问题