Results 1 to 4 of 4
  1. #1
    Codeless is offline Member
    Join Date
    Nov 2010
    Rep Power

    Default How do I add this library?

    I need to make use of JNLP classes.

    import javax.jnlp.x (where x is the class I need) results in "import cannot be resolved".

    from this I gather the library is either not part of the java api or it is but not added to the build path by default for some reason.

    I was looking online for a jnlp.jar file but have been unable to find one.

    where can I find this jar file? and if I add it to the java build path associated with my project properties will my imports work as expected?


  2. #2
    wsaryada is offline Senior Member
    Join Date
    Jun 2007
    Bali, Indonesia
    Rep Power

    Default Re: How do I add this library?

    The JNLP libraries can be found in jre/lib/javaws.jar

  3. #3
    Codeless is offline Member
    Join Date
    Nov 2010
    Rep Power

    Default Re: How do I add this library?

    thanks a million I found it. but there seems to be another problem with using the library perhaps you can help.

    my example from a textbook doesn't appear to work.

    Java Code:
    package pkg;
    // Fig. 21.1:
    // Loading, displaying and scaling an image in an applet
    import java.awt.BorderLayout;
    import java.awt.Graphics;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import javax.jnlp.FileContents;
    import javax.jnlp.FileOpenService;
    import javax.jnlp.ServiceManager;
    import javax.swing.ImageIcon;
    import javax.swing.JApplet;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JOptionPane;
    import javax.swing.JPanel;
    import javax.swing.JTextField;
    public class LoadImageAndScale extends JApplet 
       private ImageIcon image; // references image to display
       private JPanel scaleJPanel; // JPanel containing the scale-selector
       private JLabel percentJLabel; // label for JTextField
       private JTextField scaleInputJTextField; // obtains userís input
       private JButton scaleChangeJButton; // initiates scaling of image
       private double scaleValue = 1.0;  //scale percentage for image
       // load image when applet is loaded
       public void init()
          scaleJPanel = new JPanel();
          percentJLabel = new JLabel( "scale percent:" );
          scaleInputJTextField = new JTextField( "100" );
          scaleChangeJButton = new JButton( "Set Scale" );
          // add components and place scaleJPanel in applet's NORTH region
          scaleJPanel.add( percentJLabel ); 
          scaleJPanel.add( scaleInputJTextField );
          scaleJPanel.add( scaleChangeJButton );
          add( scaleJPanel, BorderLayout.NORTH );
          // register event handler for scaleChangeJButton
             new ActionListener()
                // when the JButton is pressed, set scaleValue and repaint
                public void actionPerformed( ActionEvent e ) 
                   scaleValue = Double.parseDouble( 
                      scaleInputJTextField.getText() ) / 100.0;
                   repaint(); // causes image to be redisplyed at new scale
                } // end method actionPerformed
             } // end anonymous inner class
          ); // end call to addActionListener
          // use JNLP services to open an image file that the user selects
             // get a reference to the FileOpenService
             FileOpenService fileOpenService = 
                (FileOpenService) ServiceManager.lookup( 
                   "javax.jnlp.FileOpenService" );
             // get file's contents from the FileOpenService
             FileContents contents = 
                fileOpenService.openFileDialog( null, null );
             // byte array to store image's data
             byte[] imageData = new byte[ (int) contents.getLength() ];
             contents.getInputStream().read( imageData ); // read image bytes
             image = new ImageIcon( imageData ); // create the image
             // if image successfully loaded, create and add DrawJPanel
             add( new DrawJPanel(), BorderLayout.CENTER );
          } // end try
          catch( Exception e )
          } // end catch
       } // end method init
       // DrawJPanel used to display loaded image
       private class DrawJPanel extends JPanel
          // display image
          public void paintComponent( Graphics g )
             super.paintComponent( g );
             // the following values are used to center the image
             double spareWidth = 
                getWidth() - scaleValue * image.getIconWidth();
             double spareHeight = 
                getHeight() - scaleValue * image.getIconHeight();
             // draw image with scaled width and height
             g.drawImage( image.getImage(), 
                (int) ( spareWidth ) / 2, (int) ( spareHeight ) / 2,
                (int) ( image.getIconWidth() * scaleValue ),
                (int) ( image.getIconHeight() * scaleValue ), this );
          } // end method paint
       } // end class DrawJPanel
    } // end class LoadImageAndScale
    the stack trace is

    Java Code:
    javax.jnlp.UnavailableServiceException: uninitialized
    	at javax.jnlp.ServiceManager.lookup(Unknown Source)
    	at pkg.LoadImageAndScale.init(
    	at Source)
    	at Source)
    What is this UnavailableServiceException class and why is it uninitialized?

  4. #4
    mixolydian807 is offline Member
    Join Date
    Nov 2013
    Rep Power

    Default Re: How do I add this library?

    I don't mean to dig up an old thread, but it seems that I am getting this issue as well, on this exact exercise, we read from the same book. Did you ever get this resolved?

Similar Threads

  1. Advise the Library, please
    By tmlder in forum New To Java
    Replies: 0
    Last Post: 10-11-2010, 09:53 AM
  2. Mp4 Library
    By kingler112 in forum Advanced Java
    Replies: 1
    Last Post: 04-27-2010, 02:54 PM
  3. I want to put the native library in library path in mac os x
    By Hussain Ali in forum Advanced Java
    Replies: 2
    Last Post: 02-24-2010, 07:55 AM
  4. Tell me jar file for library library org.bouncycastle.cms
    By 82rathi.angara in forum New To Java
    Replies: 10
    Last Post: 09-09-2008, 05:11 AM
  5. use a .dll library
    By Ed in forum Advanced Java
    Replies: 2
    Last Post: 07-02-2007, 03:07 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts