loading image frmo client into applet

DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 5 of 5

Thread: loading image frmo client into applet

  1. #1
    Join Date
    Nov 2003

    Exclamation loading image frmo client into applet

    Hi Everyone,

    I'm designing an applet that needs to use a JFileChooser to locate an image file on a client machine and paint that image onto a graphics canvas.

    I've read many articles about how Java doesn't allow applets to write to local disk unless they are signed with a certificate, and are accepted (I don't even know if that's the right terminology) by a user policy. Given that I only want to read a file from a local machine, is there any way I can implement a filechooser (without the process being expensive)?

    Every help is appreciated! Thanks!

  2. #2
    Join Date
    Mar 2003
    Unless the applet is signed it can do nothing outside its grey box in a web page - that means no reading, writing etc. on the client.

  3. #3
    Join Date
    Nov 2003
    I thought that might be the case... However, I need to explore some alternatives.

    In HTML there's a simple "<input type='file' ... > tag that opens up a file browser, and allows you to locate a file. Is there any way to use javascript in a webpage to read in the file (image data) given the local file path and pass on the data to the applet? Is there an alternative way to read in image data on a client machine?

    I appreciate all the help by the way... You guys (and gals) have super response times. I'm heartily impressed. Thanks!

  4. #4
    Join Date
    Mar 2003
    hmmm...I was initially going down the route - you could pass the filename from Javascript to Java, but at some point you still need to get the binary data of the image into the applet somehow.

    What's so wrong with making it a signed applet?

  5. #5
    Join Date
    Nov 2003
    Firstly, thank you very much for the replies...

    I would sign the applet, but as I understand it, it's an expensive process (maybe I'm not understanding it right!). I read you needed to buy a certificate from VeriSign or a similar company, which costs more than I'm willing to pay for a school project.

    I tried out the javascript and java applet route, and I can pass variables back and forth. However, I don't suppose there is a way in JavaScript to load an image into a variable? Is JavaScript powerful enough?

    Here's what I've tried doing to test it out:

    1. The webpage

    	function uploadImage () {
    		var image = new Image();
    		image.src = document.myForm.uploadfile;
    <body bgcolor="#A0A0FF">
    <h2><p align="center"><font color="white">Fusion of JavaScript and JApplets</font></p><hr></h2>
    <center><form name="myForm">
    <input type="button" value="Upload" name="upload" onclick="uploadImage();">
    <input type="file" name="uploadfile">
    <p align="center">
    <applet code="myApplet.class" name="myApplet" height=310 width=410 MAYSCRIPT>
    2. The Applet

    import java.applet.*;
    import java.awt.*;
    import java.awt.image.*;
    import javax.swing.*;
    public class myApplet extends Applet {
    	public static final int WIDTH=400, HEIGHT=300;
    	public BufferedImage image;
    	public void init () {
    		image = new BufferedImage(WIDTH, HEIGHT, BufferedImage.TYPE_INT_ARGB);
    		Graphics g = image.createGraphics();
    	public void paintPicture (Image newimage) {
    		Graphics g = image.createGraphics();
    		g.drawImage(newimage, 0, 0, null);
    	public static void main (String args[]) {
    		JFrame myFrame = new JFrame();
    		myApplet myapplet = new myApplet();
    		Container myPane = myFrame.getContentPane();
    		myPane.add("Center", myapplet);
    		myFrame.setSize(410, 310);
    I'm sad to say... Nothing happens ... Sorry to bombard you with all this code. It's nice to have an expert to consult! Thanks again!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
Latest Articles
Questions? Contact us.
Web Development
Latest Tips
Open Source

   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center