I am trying to create an applet from the java file, the code has to take an image from clipboard and save it into the file. The programm is working fine when executed via “java file_name”. But my goal is to implement this in to the web for helpdesk purpose. So user can click the button the programm executes saves the image from the clipboard, and then via javascript I upload it to the server.
From some googleing I understood that to make Java work on the web some modification should be done to the source code. Can someone point me in to the right direction? Or even better provide any sample of an easy applet or something?
source of java file:
[code]
import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.DataFlavor;
import java
.awt
.datatransfer
.Transferable;
import java
.awt
.datatransfer
.UnsupportedFlavorException;
import java.io.IOException;
import java.awt.*;
import java.awt.event.*;
import java.awt.image.BufferedImage;
import java.io.*;
import java.net.*;
import javax.imageio.ImageIO;
public class ImageFromClipboard {
public static void main(String[] args) throws UnsupportedFlavorException,
IOException {
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
Transferable transferable = clipboard.getContents(null);
if (transferable.isDataFlavorSupported(DataFlavor.imageFlavor)) {
System.out.println(“transferable supports image flavor”);
}
Image image = (Image) transferable.getTransferData(DataFlavor.imageFlavor);
BufferedImage bimage = new BufferedImage(image.getWidth(null), image.getHeight(null), BufferedImage.TYPE_INT_RGB);
Graphics2D g = bimage.createGraphics();
g.drawImage(image, 0, 0, null);
g.dispose();
ImageIO.write(bimage, “jpg”, new File(“C:/jv0001.jpg”));
}
}
On the HTML page i have this tag:
[code]
<applet code=”ImageFromClipboard.class” codebase = “../../../new_design/test_folder” width=”1″ height=”1″ alt=”qqq” title=”qaz”>
</applet>
Thanks in advance.