0

I'm trying to insert a Java applet on HTML page.

This is my body HTML:

<body>
    <object data="applets/pac/Teste.class" width="300" height="250">
    </object>
    This text appears on the right side of the applet
    <br clear="all"/>
    This text appears bellow the applet
</body>

And this is my Teste class:

package pac;
import java.awt.Graphics;

public class Teste extends java.applet.Applet {
  private static final long serialVersionUID = 1L;

  public void paint(Graphics g){
    g.drawString("Teste de Applet!",20,55);
  }
}

The path is correct, I'm using Tomcat server and Eclipse. When I go to the index.html, my browser downloads the Teste.class so I tried to solve it by using type="application/x-java-applet" on the object and it no longer tries to download but also the applet doesn't appear. It doesn't give me any Class not found error. I've tried embed and it's the same thing.

I'm learning Java by a book but it uses codebase on the param and it is obsolete.

Result

Eclipse & Code

I'm just a beginner, I don't know if I should use applets. Thank you.

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
dKrypt72
  • 26
  • 1
  • [Why were applets deprecated in JDK 9?](https://stackoverflow.com/questions/45535112/why-were-applets-deprecated-in-jdk-9); [Oracle reveals Java Applet API deprecation plan](https://www.theregister.co.uk/2016/08/24/oracle_reveals_java_applet_api_deprecation_plan/); Applets are deprecated, most modern browsers will simply not work with them (actively block them). Long live Html5 – MadProgrammer Mar 02 '19 at 23:57
  • If you're just starting out, then I would recommend JavaFX as a better starting point – MadProgrammer Mar 03 '19 at 00:01
  • Thank you so much. Will start to use JavaFX instead of Applets. What about Servlets? I don't know anything about it, is it worth studying it? @MadProgrammer – dKrypt72 Mar 03 '19 at 00:16
  • I’m by no means an expert, but things like nodejs semi more popular now days – MadProgrammer Mar 03 '19 at 00:51

0 Answers0