Home arrow Java arrow Page 5 - Deploying Java Applets
JAVA

Deploying Java Applets


In this second part of a three-part series on using Java with deployment frameworks, you will learn how to deploy applets in a self-contained manner, and what they are and are not typically permitted to do once they are downloaded. This article is excerpted from chapter two of Advanced Java Game Programming, written by David Wallace Croft (Apress; ISBN: 1590591232).

Author Info:
By: Apress Publishing
Rating: 4 stars4 stars4 stars4 stars4 stars / 20
April 17, 2008
TABLE OF CONTENTS:
  1. · Deploying Java Applets
  2. · Deploying as an Executable JAR
  3. · Deploying with Java Web Start
  4. · Accessing the Default Browser
  5. · Dynamic Linking Using Reflection

print this article
SEARCH DEVARTICLES

Deploying Java Applets - Dynamic Linking Using Reflection
(Page 5 of 5 )

As an alternative, you can also dynamically load the JNLP classes using reflection as shown in this code excerpt from classJnlpProxyin packagecom.croftsoft.core.jnlp.

  private static Object getBasicServiceObject ( )
  //////////////////////////////////////////////////////////////////////
  {
    try
    {
      Class  serviceManagerClass
       
= Class.forName ( "javax.jnlp.ServiceManager" );

      Method  lookupMethod = serviceManagerClass.getMethod (
        "lookup", new Class [ ] { String.class } );

      return lookupMethod.invoke (
        null, new Object [ ] { "javax.jnlp.BasicService" } );
    }
    catch ( Exception ex )
   
{
      return null;
    }
  }

ClassMethodis from core packagejava.lang.reflect.

  public static boolean showDocument ( URL url )
  //////////////////////////////////////////////////////////////////////
  {
   
if ( basicServiceObject == null )
    {
      return false;
    }

    try
    {
      Method  method = basicServiceClass.getMethod (
        "showDocument", new Class [ ] { URL.class } );

      Boolean  resultBoolean = ( Boolean ) method.invoke (
        basicServiceObject, new Object [ ] { url } );

      return resultBoolean.booleanValue ( );
    }
    catch ( Exception ex )
    {
      
ex.printStackTrace ( );

      throw new RuntimeException ( ex.getMessage ( ) );
    }
  }

By saving a singleton static reference to theBasicServiceinstance retrieved, we can then use it within our own staticshowDocument()method. The example method returnsfalseif the client platform does not support JNLP, allowing the calling code to respond with a substitute behavior.

In my opinion, dynamic linking using custom interfaces instead of reflection makes for more comprehensible code. I have found that you almost never need reflection techniques if you keep this in mind.

Please check back next week for the conclusion to this article.


DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

blog comments powered by Disqus
JAVA ARTICLES

- Java Too Insecure, Says Microsoft Researcher
- Google Beats Oracle in Java Ruling
- Deploying Multiple Java Applets as One
- Deploying Java Applets
- Understanding Deployment Frameworks
- Database Programming in Java Using JDBC
- Extension Interfaces and SAX
- Entities, Handlers and SAX
- Advanced SAX
- Conversions and Java Print Streams
- Formatters and Java Print Streams
- Java Print Streams
- Wildcards, Arrays, and Generics in Java
- Wildcards and Generic Methods in Java
- Finishing the Project: Java Web Development ...

Watch our Tech Videos 
Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 

Developer Shed Affiliates

 




© 2003-2017 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials