jQuery in Action, 2nd edition*
The moose likes Applets and the fly likes Error Diplaying TIFF in Applet through JSP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Applets
Bookmark "Error Diplaying TIFF in Applet through JSP" Watch "Error Diplaying TIFF in Applet through JSP" New topic
Author

Error Diplaying TIFF in Applet through JSP

Alpesh Khunt
Greenhorn

Joined: Nov 18, 2008
Posts: 1
Dear All,

I've been trying to display the Tif image into the WebBrowser with the help of Applet embedded into a JSP through NetBeans IDE.

To achieve this goal, I've created 2 projects "NewApplet" which contains the Applet class and "WebApplication1" which has "Index.JSP" which embeds the Applet.

If i execute Only the Applet, it displays the TIF. But if i execute the JSP, it fires the following error:
"URL Scheme is not "file" http://localhost:8084/WebApplication1/alpesh.tif""

Following is the code written NewApplet.Java:

package display;

import javax.swing.JApplet;
import java.awt.BorderLayout;
import java.awt.image.RenderedImage;
import java.io.IOException;
import javax.swing.JDesktopPane;
import javax.swing.JInternalFrame;
import javax.swing.JScrollPane;
import com.sun.media.jai.codec.ImageCodec;
import com.sun.media.jai.codec.ImageDecoder;
import com.sun.media.jai.codec.TIFFDecodeParam;
import com.sun.media.jai.widget.DisplayJAI;
import java.io.File;
import java.io.FileInputStream;
import java.net.URI;
import javax.swing.JOptionPane;

public class NewApplet extends JApplet {

@Override
public void init() {
URI FileName = URI.create(getCodeBase().toString().concat(getParameter("imageSource")));
try
{
File f = new File(FileName);

FileInputStream stream = new FileInputStream(f);

// Create a decoder using that stream.
TIFFDecodeParam tiff = new TIFFDecodeParam();
ImageDecoder dec = ImageCodec.createImageDecoder("tiff", stream, tiff);

// Get the number of pages.
int pages;
pages = dec.getNumPages();

// Set the application title.
setTitle(pages+" pages in "+filename);

// Create a JDesktop to hold the pages in internal frames.

JDesktopPane desktop = new JDesktopPane();
//getContentPane().add(desktop,BorderLayout.CENTER);
desktop.setSize(400,400);
add(desktop,BorderLayout.CENTER);
// Open all images in the TIFF into the desktop pane.
for(int i=0;i<pages;i++)
{
// Get the image.
RenderedImage ri = dec.decodeAsRenderedImage(i);
// Create and set the user interface of an internal frame.
JInternalFrame jif = new JInternalFrame("Page "+i,true,true,true,true);
jif.getContentPane().add(new JScrollPane(new DisplayJAI(ri)));
jif.setSize(400,400);
jif.pack();
jif.setVisible(true);

// Add the internal frame to the JDesktop.
desktop.add(jif);
}
// Set the application closing behaviour, frame size, and show it.
//setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(400,400);
setVisible(true);
}
catch (Exception e)
{
JOptionPane.showMessageDialog(this, e.getMessage(), "alert", JOptionPane.ERROR_MESSAGE);
}
}
}



Following is the code written Index.JSP:

<APPLET code="display.NewApplet" ARCHIVE="NewApplet.jar" width=350 height=200>
<param name ="imageSource" value="alpesh.tif"/>
</APPLET>



Any Guesses?

I've added the "dist/NewApplet.jar" in WebApplication1 through the option of "Properties->Build->Packaging" in NetBeans.

Please help!

- Alpesh
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41083
    
  43
Welcome to JavaRanch.

You can't use file I/O (classes like File and FileInputStream) to work with images loaded from a server. You'll need to do something like


Do you need to use JAI? It would be simpler if you used ImageIO (which can be made to recognize TIFF images).

Also, in the future, please UseCodeTags when posting code of any length. It is unnecessarily hard to read as it is.
[ November 18, 2008: Message edited by: Ulf Dittmer ]

Ping & DNS - my free Android networking tools app
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Error Diplaying TIFF in Applet through JSP
 
Similar Threads
loading frame/internalframe inside an internalframe
y i cannot create a MDI???
Question on displaying frames in desktops from another class...
Refreshing JInternalFrame's titlebar UI
making things not dragable