| faezbhanji |
06-14-2007 03:12 AM |
Hi Tw,
greetings from down-under, could you have a look at the code below, this is what I have put in my page, but the java app doesn't seem to want to run, it should pop-up with the SaveAs dialog, but it doesn't do anything.
Code:
<APPLET name="app1" code="savechart.class" archive="SaveChart.jar" codebase="." >
<param name="inputtop" value="0">
<param name="inputleft" value="0">
<param name="inputwidth" value="700">
<param name="inputheight" value="800">
</APPLET>
Also I'm not sure about the param names and what I should be putting there, the main in java always takes only one parameter which is args[], which in my case has 4 elements, these are then being saved into variables called inputtop, inputleft etc etc which is the reason why I show them here in the param name section I'm not sure if that's what I need to do.
I can launch the jar file from the terminal so that is working fine, which would mean something in my html code above is not right
I'm publishing my java code below, could you please compile it and save it as a jar file and see if you can get it to run.
to run it all you need to do is give the jar file 4 parameters say 0 0 500 700, these are the rectangle of the screen shot it will take of the screen.
Code:
import java.awt.image.BufferedImage;
import java.io.*;
import java.awt.*;
import java.awt.Robot;
import java.awt.Image.*;
import com.sun.image.codec.jpeg.*;
public class savechart {
public savechart(int top, int left, int width, int height) {
try {
BufferedImage capture = null;
Rectangle area = new Rectangle(top, left, width, height);
Robot robot = new Robot();
capture = robot.createScreenCapture(area);
Frame frame = new Frame();
FileDialog fDialog = new FileDialog(frame,"Save Chart",FileDialog.SAVE);
fDialog.setFile("*.jpeg");
fDialog.setVisible(true);
fDialog.requestFocus();
String A = fDialog.getDirectory();
String B = fDialog.getFile();
String C = System.getProperty("file.seperator");
String imgFile = fDialog.getDirectory() + fDialog.getFile();
FileOutputStream out = new FileOutputStream(imgFile);
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
encoder.encode(capture);
out.flush();
out.close();
System.exit(0);
} catch (Exception exc){
System.out.println("errors ");
exc.printStackTrace();
}
finally {
System.out.println("Error Creating Image");
System.exit(0);
}
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
int inputtop = Integer.parseInt(args[0]);
int inputleft = Integer.parseInt(args[1]);
int inputwidth = Integer.parseInt(args[2]);
int inputheight = Integer.parseInt(args[3]);
new savechart(inputtop,inputleft,inputwidth,inputheight);
}
}
|