Win a copy of JDBC Workbook this week in the JDBC and Relational Databases forum
or A Day in Code in the A Day in Code forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
  • Piet Souris
  • salvin francis
  • fred rosenberger

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

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));;
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
change it to a frame and debug. You have to work to get an answer though
Liar, liar, pants on fire! refreshing plug:
Devious Experiments for a Truly Passive Greenhouse!
    Bookmark Topic Watch Topic
  • New Topic