Java
  Home arrow Java arrow Page 5 - Deploying Java Applets
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
JAVA

Deploying Java Applets
By: Apress Publishing
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 5
    2008-04-17

    Table of Contents:
  • Deploying Java Applets
  • Deploying as an Executable JAR
  • Deploying with Java Web Start
  • Accessing the Default Browser
  • Dynamic Linking Using Reflection

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    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.

       · This article is an excerpt from the book "Advanced Java Game Programming," published...
     

    Buy this book now. This article is excerpted from chapter two of Advanced Java Game Programming, written by David Wallace Croft (Apress; ISBN: 1590591232). Check it out today at your favorite bookstore. Buy this book now.

    JAVA ARTICLES

    - 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 ...
    - Generics and Limitations in Java
    - Getting Started with Java Web Development in...






    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway
    Stay green...Green IT