Embedding a JNLP file in an HTML page - Java Applet

Java examples for Applet:JNLP

Description

Embedding a JNLP file in an HTML page

JNLPExample.jnlp

<?xml version="1.0" encoding="UTF-8"?>
<jnlp href="JNLPExample.jnlp">
    <information>
        <title>Embedded JNLP File</title>
        <vendor>Sample Vendor</vendor>
    </information>
    <resources>
        <j2se version="1.7" />
        <jar href="JNLPAppletExample.jar" 
             main="true" />
    </resources>
    <applet-desc 
         name="Embedded JNLP Example"
         main-class="packt.JNLPAppletExample"
         width="500"
         height="500">
     </applet-desc>
      <update check="background"/>
</jnlp>

Demo Code

import java.applet.Applet;
import java.awt.Button;
import java.awt.GridLayout;
import java.awt.Label;
import java.awt.TextArea;
import java.awt.TextField;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class Main extends Applet {
    @Override//ww  w  . j  ava2 s. c  o m
    public void init() {
        this.setLayout(new GridLayout(3,2));
        this.add(new Label("Subtotal = "));
        this.add(new Label("Tax Rate = "));
    }
}
<HTML>
<HEAD>
<TITLE>Embedded JNLP File Example</TITLE>
</HEAD>
<BODY>
<H3>Embedded JNLP Applet</H3>
<script src="http://www.java.com/js/deployJava.js"></script>
<script>        
    var jnlpFile = "JNLPExample.jnlp";
    deployJava.createWebStartLaunchButtonEx(jnlpFile);
</script>
<script>
    var attributes = {} ;
    var parameters = {jnlp_href: 'JNLPExample.jnlp',
        jnlp_embedded: 'hash string'};
    deployJava.runApplet(attributes, parameters, '1.7');
</script>
</BODY>
</HTML>

Related Tutorials