Combining Jar Files

This shows how we manipulate jar files using the jar program that is part of the Java JDK. To see the applets in action visit the web page here, enable Java and view the Console. Move the cursor just under the "Back Buffer Demo" title to view the middle applet.

See below (1) the code of our batch file used to process the jar files, (2) the HTML file used to display three applets and (3) a screenshot. The jar program can take several single character parameters passed on the command line or in a batch file. The characters x, v, f and c represent extract, verbose, file and create, respectively.

Batch file code

jar xvf threads.jar threads/ThreadApplet.class
jar xvf back_buffer.jar back_buffer/BackBufferApplet.class
jar xvf draw.jar draw/DrawApplet.class
jar cvf demo.jar back_buffer/BackBufferApplet.class threads/ThreadApplet.class 
draw/DrawApplet.class

Web page showing three applets from one jar file

<!DOCTYPE html SYSTEM "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <title>Applet Demonstrations</title>
  </head>
  <body>
    <center>
      <h3>Draw Demo</h2>   
      <p>Java must be enabled.</p> 
      <table>
        <tr>
          <td><h4 align="center">Draw Demo</h4> 
                 <applet archive="demo.jar" code="draw/DrawApplet.class" 
                      width="300" height="300" /> </td>
         </tr>
         <tr>
           <td><h4 align="center">Back Buffer Demo</h4>  
                  <applet archive="demo.jar" code="back_buffer/BackBufferApplet.class" 
                       width="200" height="200" /></td>
         </tr>
         <tr>
            <td><h4 align="center">Thread Demo</h4> 
                   <applet archive="demo.jar" code="threads/ThreadApplet.class" 
                         width="200" height="200" /></td>
         </tr>     
      </table>
    </center>
  </body>
</html>

Screenshot

Screenshot showing output

Screenshot showing graphical and text output

Programming - a skill for life!

Mouse and keyboard input, graphics (including Graphics2D), threads and widgets in Oxygene for Java applets