| Author |
Help... Urgent.. PLEASE... Applet Code....
|
sam patel
Ranch Hand
Joined: Jun 13, 2002
Posts: 103
|
|
Hi, I am kind of new to java... I found this JApplet code which writes text to a image file...But i want to run this without using the applet...How can i covert this JApplet to an old fashion java Application... I would appreciate if someone can show me how... I am posting the code below.....You will need JAI API... Thanks in advance.... ====================================================================== import java.awt.*; import java.awt.event.*; import com.sun.image.codec.jpeg.*; import com.sun.media.jai.codec.*; import javax.media.jai.*; import java.awt.image.BufferedImage; import java.awt.image.RenderedImage; import java.awt.image.DataBuffer; import java.awt.geom.GeneralPath; import java.io.*; import javax.swing.*; import java.awt.image.renderable.ParameterBlock; public class JPEGJai extends JApplet { // private static Image img; public static final String DEFAULT_FILE = "blank.jpg"; private static RenderedImage img; public void init() { setBackground(Color.white); String fileName = DEFAULT_FILE; // Read the image from the designated path. System.out.println("load image from '" + fileName+"'"); img = (RenderedImage)JAI.create("fileload", fileName); } public void paint(Graphics g) { Graphics2D g2 = (Graphics2D) g; Dimension d = getSize(); g2.setBackground(getBackground()); g2.clearRect(0, 0, d.width, d.height); g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); int w = d.width; int h = d.height; RenderedImageAdapter ria = new RenderedImageAdapter(img); BufferedImage bi = ria.getAsBufferedImage(); Graphics2D big = bi.createGraphics(); big.setFont(new Font("Dialog", Font.PLAIN, 20)); big.setColor(Color.black); big.drawString("Data/Time Created:" + new java.util.Date(), 80, 210); big.drawString("POLICY NUMBER: 1711215 NAME OF CALLER: BENEFICIARY", 80, 230); big.drawString("Requested: Loan Request Current Loan Value: $0.00", 80, 270); g2.drawImage(bi, 0, 0, this); try { File file = new File("test.tiff"); FileOutputStream out = new FileOutputStream(file); TIFFEncodeParam params = new TIFFEncodeParam(); params.setCompression(TIFFEncodeParam.COMPRESSION_NONE); ImageEncoder encoder = ImageCodec.createImageEncoder("TIFF",out, params); if(encoder == null) { System.out.println("imageEncoder is null"); System.exit(0); } encoder.encode(bi); } catch (Exception ex) { g2.setColor(Color.red); g2.drawString("write permissions on images/test.jpg?", 5, h*2-5); } } public static void main(String argv[]) { final JPEGJai demo = new JPEGJai(); demo.init(); JFrame f = new JFrame("JAI Demo - JPEGJai"); f.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) {System.exit(0);} }); f.getContentPane().add("Center", demo); f.pack(); f.setSize(new Dimension(400,300)); f.show(); } }
|
 |
Francis Siu
Ranch Hand
Joined: Jan 04, 2003
Posts: 867
|
|
hi sam Actually, Urgent.. almost without answer You can try it,if it does not work,you can post it again [ May 16, 2003: Message edited by: siu chung man ] [ May 16, 2003: Message edited by: siu chung man ]
|
Francis Siu
SCJP, MCDBA
|
 |
 |
|
|
subject: Help... Urgent.. PLEASE... Applet Code....
|
|
|