1

I'm writing an simple applet using JDK-14 in MyApp.java:

public class MyApp extends Applet {
    public void paint(Graphics g) {
        g.drawString("My App", 20, 20);
    }
}

Then I created index.html and add the following line to <head> tag:

<applet code="MyApp.class" width=200 height=600></applet>

When I saved and reload my web page in Chrome, nothing displayed.

Then, I tried to execute the MyApp.java run it in Terminal, the following error occured:

Note: MyApp.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Error: Main method not found in class MyApp, please define the main method as:
   public static void main(String[] args)
or a JavaFX application class must extend javafx.application.Application

I read that the applet doesn't require public static void main(String[] args).

Is there any problem with Chrome or I didn't import something ?

HoangNguyen
  • 21
  • 1
  • 6
  • 4
    [Applets are deprecated.](https://docs.oracle.com/en/java/javase/14/docs/api/java.desktop/java/applet/package-summary.html) You will need to use an older browser, and I suspect an older version of Java which supports the browser plug-in, in order to work with applets. You would be better off following tutorials which don’t ask you to work with applets at all. – VGR Apr 16 '20 at 18:00
  • 3
    In addition to what VGR said, back before applets were deprecated, you didn't test them by running them but rather by viewing them with [appletviewer](https://docs.oracle.com/javase/10/tools/appletviewer.htm) which was deprected in JDK 9 and removed in JDK 11. – David Conrad Apr 16 '20 at 18:46
  • 2
    Besides the points well covered by @VGR & David Conrad, note that the HTML is invalid. An applet element should ***not*** (even when browsers **did** support the applet plug-in) be put in the `head` of the document. Why code an applet? If it is due to the teacher specifying it, please refer them to [Why CS teachers should **stop** teaching Java applets](http://programmers.blogoverflow.com/2013/05/why-cs-teachers-should-stop-teaching-java-applets/). (Note: that document was written long *before* applets were deprecated.) – Andrew Thompson Apr 17 '20 at 01:34

1 Answers1

0

Applet is deprecated since Java 9 check here

If still you want to use applet then you must go through java 8 and use browsers with older version which supports Applet (not recommended).

Niravdas
  • 371
  • 2
  • 19