1

I asked a question on here once before and got some great help and advice from a lot of knowledgeable people so I thought I'd try this again with another programming issue I'm having.

Here is the basic problem. I've created a small Java applet that takes four images and combines them into one large image. To be more specific, I combine four images into one large image that will fold up to be a greeting card when printed out. Everything works just fine, but I'm going to be embedding the applet on my website and so I'll have users select the four images they want from a list of images on my website, and then with their selections I'll create the large image.

Now here's the trouble... when I create the large image I want the user to be able to download it. Is it necessary to create a signed applet? And if so, how do I go about signing my applet? Or is it somehow possible for the applet to just display the image in such a way so the user can just right-click the image and save it to their file system. Any advice/suggestions would be much appreciated!!

marko
  • 9,029
  • 4
  • 30
  • 46
Keith Salmon
  • 89
  • 3
  • 9

3 Answers3

3

There is no need to sign the applet if the image is loaded from the same location that the applet class itself is downloaded. There would be a problem however, saving the image locally from an unsigned applet. For that functionality, you would need to sign the applet.

Alternatively, for applets running in a web browser, the image could be displayed in a separate browser frame using:

applet.getAppletContext().showDocument(imageURL, frameTarget);

From this page/frame, the image could then be saved locally using Javascript.

Community
  • 1
  • 1
Reimeus
  • 158,255
  • 15
  • 216
  • 276
  • Yes, the four images come from the same location as the applet and so then I wanted to create the new image somewhere were it could be easily downloaded. Your solution of the displaying it in a separate frame sounds like an excellent idea. I may be back with another question though, as I haven't created new browser frames via a Java applet before. – Keith Salmon Jan 18 '13 at 01:33
  • *"the image could be displayed in a separate browser"* While base 64 encoding has limits in older browsers, it might be the best approach for this. – Andrew Thompson Jan 18 '13 at 02:09
1

Depending on Java and browser version, I see 3 options:

  1. Digitally sign the Jar and encourage the end user to trust the digitally signed code.
  2. Jar the app., deploy it using Java Web Start and use the JNLP API services to save the resulting image. This can be done with a free floating applet since Java 1.2, or an embedded applet since 1.6.0_10+. Here is a demo. of the file services. GIFanim also offers an embedded applet that uses the services for saving animated GIFs.
  3. Encode the image as a Base64 URL to display it direct in a web page. This requires a more recent browser, older browsers put a 32Kb limit on the image size. J2SE only had a method added recently, that could do the conversion for us. See DatatypeConverter.printBase64Binary(byte[])
Community
  • 1
  • 1
Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
0

To write files to a file system, signing an applet is necessary.

However it is quite easy to self sign applets and unless your users are extremely cautious, self signing would work.

Follow these intructions to sign an applet. P.S these instructions are for a linux setup. You might need to set up environment variables in windows.

Jar signing link

Osama Javed
  • 1,432
  • 1
  • 16
  • 21