0

My Java applet (called NameInLights.class) does not display when I load my HTML page. The .class file definitely exists, and the other parts of my HTML display in their correct places on the page. Java is enabled in my browser and the applet works fine in the AppletViewer.

Here is my java code:

import java.util.Random;
import java.awt.*;
import java.applet.*;
public class NameInLights extends Applet {

    private static final long serialVersionUID = 1L;
    Random r = new Random();
    String name = "Imulsion";//must keep my real name secret! :)
    public void init(){
        setSize(500,500);
    }
    public void paint(Graphics g){
    g.setColor(new Color(r.nextInt(255),r.nextInt(255),r.nextInt(255)));
    g.setFont(new Font("Comic sans ms",Font.BOLD,55));  
    g.drawString(name,125,250);
    for(int loop=0;loop<500;loop++)
    {
        int red = r.nextInt(255);
        int green = r.nextInt(255);
        int blue = r.nextInt(255);
        int x = r.nextInt(500);
        int y = r.nextInt(500);
        g.setColor(new Color(red,green,blue));
        g.setFont(new Font("Times New Roman",Font.BOLD,24));
        g.drawString("*",x,y);
    }
    }
}

And here is my HTML:

<html>
 <body>
    <p>
     Here comes an awesome applet!
    </p>
    <br />
    <br />
    <applet code="NameInLights.class" width = 500 height = 500>
    </applet>
    <button type = "button" onclick = "window.location.reload()">
     Change applet colours
    </button>
 <body>
<html>

Why does it not display?

4
  • Google chrome. It asks me if I should allow java to work on the page, obviously i click yes. I tried on internet explorer that didnt work either Commented Jul 29, 2012 at 16:12
  • Have you tried clearing browser and Java cache? Commented Jul 29, 2012 at 16:21
  • Check the Java Console for output. And better to add 50 as a bounty, than post duplicate questions. Commented Aug 5, 2012 at 8:58
  • If I did, I would lose 50 rep and then only have 6. Commented Aug 8, 2012 at 6:35

2 Answers 2

1

Ok, google Chrome officially does not support deprecated tag applet. Use tag object instead.

Sign up to request clarification or add additional context in comments.

2 Comments

So what would my object tag look like?
I just tested Google Chrome (version 21.0.1180.60 m) using a plain applet element in simple HTML and it works just fine. Perhaps you mean that Chrome does not ship with the JRE? That makes perfect sense. A browser should not ship with every conceivable plug-in, instead users should install them as per need (prompted by HTML).
0

As a first look, you can use:

appletviewer your_html_file.html

Then, you probably need to download a plugin for your browser:

http://www.oracle.com/technetwork/java/index-jsp-141438.html

1 Comment

<html> <body> <h1>heres a cool applet</h1> <hr /> <object codetype="application/java" classid = "java:NameInLights.class" width = "500" height = "500"> </object> </body> </html>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.