Win a copy of Head First Agile this week in the Agile forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Help... Urgent.. PLEASE... Applet Code....  RSS feed

sam patel
Ranch Hand
Posts: 103
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 java.awt.image.BufferedImage;
import java.awt.image.RenderedImage;
import java.awt.image.DataBuffer;
import java.awt.geom.GeneralPath;
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() {
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.clearRect(0, 0, d.width, d.height);
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.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();
ImageEncoder encoder = ImageCodec.createImageEncoder("TIFF",out, params);
if(encoder == null) {
System.out.println("imageEncoder is null");

} catch (Exception ex) {
g2.drawString("write permissions on images/test.jpg?", 5, h*2-5);


public static void main(String argv[]) {
final JPEGJai demo = new JPEGJai();
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.setSize(new Dimension(400,300));;
Francis Siu
Ranch Hand
Posts: 867
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!