• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Plot Curve in Servlet using Graphics2D

 
Apple Khoa
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5125
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Apple Khoa wrote:


You're trying to create a method inside another one. You can't do that.
 
Ulf Dittmer
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Apple Khoa
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5125
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic