My applets do not display in my browser (Google Chrome)

2.6k Views Asked by At

I had an issue a couple of days ago with Java applets. Here is my code:

Hello.java class file

//Reference the required Java libraries
 import java.applet.Applet; 
 import java.awt.*; 
 import java.io.*;

 //The applet code
  public class Hello extends Applet {

     public static void main(String[] args)  {
       //new Main();
       System.out.println("Hello worlds");
    }
  } 

And the HTML file applet.html

<HTML>
 <HEAD>
 <TITLE> My First Java Applet </TITLE>
 </HEAD>
 <BODY>
 <P>Here's my first Java Applet@@@@: <BR><BR><P>
 <applet code ="Hello.class"  width="200" height ="200"> APPLET </applet>
 </BODY>
 </HTML>

and I had taken the issue,

 "Error,click for details."

and another issue I take when I'm trying to run my applet from command prompt is

C:\Users\Andreas>cd C:\xampp\htdocs\mysite\
C:\xampp\htdocs\mysite>appletviewer applet.html

after I click enter the appletviewer window is opening but does not displaying anything.It just says: "Applet started"

I Have installed the latest version of java and Java SDK, and I also double-check this in java.com.

I'm running this locally.

Can anyone help me? What I'm missing? In other websites which are running java applets its just asking for permission at the top of the browser and that's all.

I'm trying to get this to work in order to write code about multitasking (any other ideas about multitasking for a website?)

1

There are 1 best solutions below

0
On

In the Applet class, main() method is not there. Please try to execute the below example:-

import java.applet.*;
import java.awt.*;

public class HelloWorldApplet extends Applet{

public void paint(Graphics g){

g.drawString("hello world" , 25, 50);

  }
}

-

<html>
<title>Applet application</title>
<hr>
<applet code="HelloWorldApplet.class" width="320" height="120">

If the browser is not java enabled then this message will be printed.

</applet>
<hr>
</html>