This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Help... Urgent.. PLEASE... Applet Code.... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Help... Urgent.. PLEASE... Applet Code...." Watch "Help... Urgent.. PLEASE... Applet Code...." New topic

Help... Urgent.. PLEASE... Applet Code....

sam patel
Ranch Hand

Joined: Jun 13, 2002
Posts: 103
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

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
jQuery in Action, 2nd edition
subject: Help... Urgent.. PLEASE... Applet Code....
Similar Threads
Need help on print , scrollbar for my applet
combining tif files with java
Applet(with images) running problem at Client
Am merging images using JAI pls tell it has merging first page of image
Help... Urgent.. PLEASE... Applet Code....