0

I created a small applet for my sister's blog that flashes colors randomly. She wants to set it as her background for her webpage. I've already figured out how to find the size of a web page and all that, but how do I declare the applet's width and height to be values of my functions?

Here's the tester page code:

<html>
<head>
<title>Flashing colors</title>
<script type="text/javascript">
var w = window,
    d = document,
    e = d.documentElement,
    g = d.getElementsByTagName('body')[0],
    x = w.innerWidth || e.clientWidth || g.clientWidth,
    y = w.innerHeight|| e.clientHeight|| g.clientHeight;
function getWidth(){
    return x;
}
function getHeight(){
    return y;
}
</script>
</head>

<body>

//Here's the problem

<applet code="FlashingColors.class" width=getWidth() height=getHeight()>
</applet>

</body>
</html>

I have no experience in html or javascript, but plenty in Java. If someone could explain what to do and why it works, that would be nice.

Update: At this point, I do realize that one wouldn't use an applet, but at this point I just want to figure out how to make it work, because I am curious and want to learn.

1
  • Don't use a Java applet for this. It will be a mess.. (considers) well I suppose random flashing BG colors will be a mess anyway, but don't create it with an applet. It can all be done using JS. Commented May 18, 2013 at 14:49

1 Answer 1

2

You can't reliably layer HTML content on top of Java applets in a web page. So this won't work anyway.

Learn a little bit more Javascript and use that to implement the same effect. It will work much better. (To get you started: You can assign an HTML color value directly to the document.body.style.backgroundColor property.)

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

1 Comment

"(JS) It will work much better." +1 to that. A Java applet is completely wrong for this.

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.