aspose file tools*
The moose likes Other Open Source Projects and the fly likes Plot Curve in Servlet using Graphics2D Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Other Open Source Projects
Bookmark "Plot Curve in Servlet using Graphics2D" Watch "Plot Curve in Servlet using Graphics2D" New topic
Author

Plot Curve in Servlet using Graphics2D

Apple Khoa
Ranch Hand

Joined: Jul 27, 2011
Posts: 37
Hi all,

I am trying to plot a quadratic curve in a servlet which will display the output as a pdf file. I am not sure if Graphics2D in java.awt.Graphics2D can be used in servlet, so i gave it a try. I face some problems as described below:

My servlet code:


Error shown by Eclipse:
public void paint(Graphics g)

Suggestion by Eclipse: "Void is an invalid type for the variable paint" (This wasn't a problem if it is a normal Java file, not a servlet)

Error shown by Eclipse:
doc.add(new Paragraph(quadcurve));

Suggestions by Eclipse:
1. "Remove argument to match Paragraph();" > Doing so will remove the quadcurve
2. "Change type of quadcurve to float" > But quadcurve is not a float in the first place.

Any help to resolve this issue will be greatly appreciated.

Thanks in advance.
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4642
    
    5

Apple Khoa wrote:


You're trying to create a method inside another one. You can't do that.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42291
    
  64
You can't have a method inside of a method.

I'm not quite sure what you're trying to do, but I very much doubt that it's going to work. The Servlet API has no provisions for a "paint" method.


Ping & DNS - my free Android networking tools app
Apple Khoa
Ranch Hand

Joined: Jul 27, 2011
Posts: 37
Ulf Dittmer wrote:You can't have a method inside of a method.

I'm not quite sure what you're trying to do, but I very much doubt that it's going to work. The Servlet API has no provisions for a "paint" method.


I am trying to draw Quadratic curves with my Servlet which will then output the curve in pdf format. I thought I can achieve that using Graphics2D in the java.awt.Graphics2D. So, can I say that Graphics2D is not supported in servlet?
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4642
    
    5

You can construct a BufferedImage, obtain its Graphics2D and draw to it.

You can then save the image or write it to a stream using ImageIO.
 
 
subject: Plot Curve in Servlet using Graphics2D