Following is just a simple program using DisplayJAI to view image formats... and I select a text file with this program.
Question ID A ------------- How to check whether the image1 was created successfully. Text files aren't image files.
Question ID B ------------- Same as above question.
Question ID C ------------- This is the biggest problem. When I selected the text file, the command prompt started to show the stacktrace which I believe i didn't check the exceptional case somewhere. Can someone give me an answer on how to detect such errors and stop printing stack trace in my command prompt. I use JDK 1.4 and JAI 1.1.2 or something. Please help!
// Question ID A - Start image1 = JAI.create("stream", fileSeekableStream); // Question ID A - End
ParameterBlock params = new ParameterBlock(); params.addSource(image1); params.add(0.5F); // x scale factor params.add(0.5F); // y scale factor params.add(0.0F); // x translate params.add(0.0F); // y translate Interpolation interp = Interpolation.getInstance(Interpolation.INTERP_NEAREST);
// Question ID B - Start source = JAI.create("scale", params); // Question ID B - End
// Question ID C - Start set((RenderedImage) source,0,0); // Question ID C - End } }
public void paintComponent(Graphics g){ super.paintComponent(g); }
public static void main (String args[]){ JFrame jf = new JFrame("Sample"); Tempo tmp = new Tempo(); tmp.loading(); jf.getContentPane().add(tmp); jf.setSize(200,200); jf.setVisible(true); }
public Dimension getPreferredSize(){ return new Dimension(200,200); } }