manipulation of Images in servlets

I have a application which can convert object into image (.jpg/.gif). Acme.Jpm.Encoder.* can download from
http://www.acme.com/java/software/Acme.JPM.Encoders.GifEncoder.ht
ml

import java.awt.*;
import Acme.JPM.Encoders.*;
import java.io.*;
import java.net.*;
import java.util.*;

public class Converter extends Frame
{
  TextCanvas canvas;
  String str = "VirtualSoft";
  Image bgImg;
  int width;
  int height;

  public Converter()
  {
    setVisible(true);
    setSize(300,300);
    GraphicsEnvironment gEnv = GraphicsEnvironment.getLocalGraphicsEnvironment();
    String envfonts[] = gEnv.getAvailableFontFamilyNames();
    setFont(new Font("Speedball Regular",Font.BOLD,48));

    String imgFile = "images/back42.jpg";
    bgImg = Toolkit.getDefaultToolkit().getImage(imgFile);
    MediaTracker mt = new MediaTracker(this);
    mt.addImage(bgImg,0);
    try
    {
      mt.waitForAll();
    }
    catch(Exception e){}
    canvas = new TextCanvas();
    add(canvas);
    repaint();
    canvas.createImage(str,bgImg,width,height);
  }
  public static void main(String args[])
  {
    new Converter();
  }

  private void setImgSize(int width, int height)
  {
     this.width=width;
     this.height=height;
  }

  public void paint(Graphics g){
    super.paint(g);
    Graphics2D g2 = (Graphics2D) g;
    FontMetrics metrics = g2.getFontMetrics();
    height = metrics.getHeight();
    width  = metrics.stringWidth(str);
    setImgSize(width,height);
  }
}

class TextCanvas extends Canvas
{
  int width;
  int height;
  String str;
  Image bgImg;

  TextCanvas()
  {
    setSize(200,200);
    setVisible(true);
    setBackground(Color.blue);
    GraphicsEnvironment gEnv = GraphicsEnvironment.getLocalGraphicsEnvironment();
    String envfonts[] = gEnv.getAvailableFontFamilyNames();
    setFont(new Font("Vivacious Regular",Font.BOLD,48));
  }
  public void createImage(String str,Image bgImg,int width,int height)
  {
    this.str=str;
    this.bgImg=bgImg;
    this.width=width;
    this.height=height;
    try
    {
      Graphics g;
      System.out.println(height);
      System.out.println(width);
      OutputStream fos =  new FileOutputStream("c:/Temp/Speedball.gif");
      Image img = this.createImage(width+20,height+10);
      g = img.getGraphics();
      this.paint(g);
      GifEncoder gifEncoder = new GifEncoder(img,fos);
      gifEncoder.encode();
      fos.flush();
      fos.close();
    }
    catch(Exception e)
    {
       System.out.println("Error: "+e.toString());
    }
  }

  public void paint(Graphics g)
  {
    super.paint(g);
    g.drawImage(bgImg,0,0,this);
    g.drawString(str,5 ,height-10);
  }
}

it work fine but when I want to do this work through servlets it was given exception on getGraphics().
I am trying to do this because I need a way to save and manipulation of images (i,e rotate, etc) on the server.  I am trying to avoid using an applet, and keep the returned servlet code pure html.

Thanks

siayubiAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

siayubiAuthor Commented:
Adjusted points to 50
0
heyhey_Commented:
you can access the real UI resources after the Frame / Component peer (that is the real underlying OS dependand implementation) is created. usually it is created when you make the Frame / component visible. you can create them manually with
frame.addNotify();

btw. you may have some additional problems in Unix / XWindows enviroment.

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
siayubiAuthor Commented:
But when I want to get Server's font through the following code,

GraphicsEnvironment gEnv = GraphicsEnvironment.getLocalGraphicsEnvironment();
String envfonts[] = gEnv.getAvailableFontFamilyNames();

It will give the following exceptions

java.lang.ClassNotFoundException: Unable to find class java.awt.GraphicsEnvironment at java.lang.Throwable
0
Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

siayubiAuthor Commented:
I am working in the Windows NT environment.
0
heyhey_Commented:
check your environment.
GraphicsEnvironment does NOT exist in JDK 1.1
0
siayubiAuthor Commented:
I am working in JDK 1.2, It work fine in previous application but not the servlet.
0
siayubiAuthor Commented:
and working in JSDK 2.0 environment....
0
siayubiAuthor Commented:
and working in JSDK 2.0 environment....
0
siayubiAuthor Commented:
and working in JSDK 2.0 environment....
0
siayubiAuthor Commented:
and working in JSDK 2.0 environment....
0
siayubiAuthor Commented:
and working in JSDK 2.0 environment....
0
siayubiAuthor Commented:
and working in JSDK 2.0 environment....
0
siayubiAuthor Commented:
Thanks alot for pointing me towards the right solution.
can you give me your email address, my mailing address is
siayubi@hotmail.com
Once again alot of thanks
0
heyhey_Commented:
my e-mail: heyhey_@iname.com
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java EE

From novice to tech pro — start learning today.