|
Java™ by example!
|
|
|
How do I change the Applet background color to the HTML background color?
The applet background is adapted to the HTML background color. It is passed to the applet by an initial parameter. Clicking the button will call a Javascript function that will call the Applet's method "newBackground(String color)" so that it dynamically adapt the backgound.
In order to achieve the same background color of the applet and the HTML page, the HTML background color should be passed to the applet at initialization time. This can be done by an applet parameter at the HTML side, and by calling the getParameter(String par) method at the applet side, i.e. within the init() method and a further call to i.e. newBackground(String color) will perform the color change. In case of dynamic HTML pages, where the background color dynamically changes, the newBackground(String color) method should directly be called each time the HTML background changes. In this example we call it from the JavaScript function setColor() directly.
Inside your HTML page:
AppletTransparentDemo.java:
Further Information
Author of answer: Sandor Gyarmati
Comments to this answer are only viewable by members. Login or become a member!
|
|
|
|
|