Creating a simple "skinned" applet

Skin Look And Feel provides a simple way to skin your existing applets. When you download Skin Look And Feel you are provided with the look and feel part but also with utility classes to help you in enabling skins in your applications.

Skinit has shipped with SkinLF since version 0.3 and has enabled easy skinning of applications.

But Skinit is useless for applets.

Fortunately, SkinApplet is here. The goal of SkinApplet is to offer a simple way to set the themepack of your applet using the themepack applet tag. SkinApplet extends JApplet and adds the required method to load a themepack.

Here is the most simple example applet using SkinApplet:

import com.l2fprod.gui.SkinApplet;
import java.awt.BorderLayout;
import java.net.URL;
import javax.swing.*;


/**
 * SimpleApplet.
 * An applet showing how to set the Skin Look And Feel
 * using a themepack provided as an applet parameter or
 * using the themepack bundled in the applet jar file.
 */
public class SimpleApplet extends SkinApplet {

  public SimpleApplet() {
  }

  /**
   * The init() method is called by the Applet container (appletviewer,java plugin,...).
   * In this method, we will set up the look and feel and tries to load a theme pack
   */
  public void init() {
    try {
      initSkin(SkinApplet.THEMEPACK_TAG);
      createUI();       
    } catch (Exception e) {
      e.printStackTrace();
    }    
  }

  public void createUI() {
    getContentPane().setLayout(new BorderLayout(3, 3));
    getContentPane().add("Center", new JButton("Congratulations !"));
  }

}

Here is the SimpleApplet.html used to display the applet:


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Simple Applet</title>
</head>
<body>
<h1>Simple Applet</h1>
<applet codebase="." archive="skinlf.jar,simpleapplet.jar"
code="SimpleApplet.class" width="200" height="30">
      <param name="themepack" value="themepack.zip">
    </applet>
  </body>
</html>

Test the Simple Applet.

Skin Look And Feel requires the browser to support at least JRE 1.2. The Java plugin is recommended to experience the applet.