2
votes
//********************************************************************
//  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);
   }
}

Error: Main method not found in class Einstein, please define the main method as: public static void main(String[] args) or a JavaFX application class must extend javafx.application.Application

How can I fix this?

3

3 Answers

0
votes

I believe you are using Eclipse to run this program. There you right click anywhere in the class above, do Run As -> Java Applet And it will run fine.

Below is the output I got while running your program above.

enter image description here

0
votes

You need to add the entry main method to your class if you want to run it like as an application java:

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

But if you want to run it like a Applet application use run java applet.

0
votes

You need an init(){} function. Also from what i've seen on the web people use 'Applet' not JApplet. I don't recommend making java applets as of chrome no longer supports plugins like Java and Unity Web Player.