Anuj Kumar
how to draw lines,circles, rectangles on JSP (using Java Graphics)
2 Answer(s)      4 years and 7 months ago
Posted in : JSP-Servlet

how to draw lines,circles, rectangles on JSP (using Java Graphics)

Advertisement
View Answers

December 14, 2010 at 12:50 PM


Hello Anuj

Try the Following Code :

image.jsp

<%@ page contentType="image/jpeg"
import="java.awt.*,java.awt.image.*,
com.sun.image.codec.jpeg.*,java.util.*"
%>
<%
// Create image
int width=200, height=200;
BufferedImage image = new BufferedImage(width,
height, BufferedImage.TYPE_INT_RGB);
// Get drawing context
Graphics g = image.getGraphics();
// Fill background
g.setColor(Color.white);
g.fillRect(0, 0, width, height);
// Create random polygon
Polygon poly = new Polygon();
Random random = new Random();
for (int i=0; i < 5; i++) {
poly.addPoint(random.nextInt(width),
random.nextInt(height));
}
// Fill polygon
g.setColor(Color.cyan);
g.fillPolygon(poly);
// Dispose context
g.dispose();
// Send back image
ServletOutputStream sos = response.getOutputStream();
JPEGImageEncoder encoder =
JPEGCodec.createJPEGEncoder(sos);
encoder.encode(image);
%>

Note- Replace the Code at line number 8 with "BufferedImage image = new BufferedImage(width,height, BufferedImage.TYPE_INT_RGB); "



December 14, 2010 at 12:52 PM


Don't need to replace the code at line number 8.

It was mistakenly mentioned.

Sorry for the inconvenience.










Related Tutorials/Questions & Answers:
how to draw lines,circles, rectangles on JSP (using Java Graphics)
how to draw lines,circles, rectangles on JSP (using Java Graphics)  how to draw lines,circles, rectangles on JSP (using Java Graphics)   ... context Graphics g = image.getGraphics(); // Fill background g.setColor(Color.white
how to draw lines,circles, rectangles on JSP.
how to draw lines,circles, rectangles on JSP.  how to draw lines,circles, rectangles on JSP. Kindly provide solutions asap
Advertisements
How to draw in jPanel? swing/graphics Java
How to draw in jPanel? swing/graphics Java  How to draw in jPanel? (swing/graphics Java
how to make multiple rectangles
how to make multiple rectangles  I,m a beginner , m sorry... of the array list in rectangles. as in each element should be in different rectangles... Output() { //Set JFrame title setTitle("Draw A Rectangle In JFrame
draw a sine wave using jsp
draw a sine wave using jsp  hai frds.. i need to draw a sine wave by using jsp.. the values X and Y co-ordinate is present in database i have fetch those values from that then display the sine wave graph according
Program to draw rectangle on each mouse click and erase priviouse rectangles
Program to draw rectangle on each mouse click and erase priviouse rectangles  Program to draw rectangle on each mouse click and erase previous rectangle on next mouse click
draw the running or moving graph using database in jsp
draw the running or moving graph using database in jsp  hi my question is how to draw the running or moving graph using jsp and take x and y co-ordinate value from database
draw the running or moving graph using database in jsp
draw the running or moving graph using database in jsp  hi my question is how to draw the running or moving graph using jsp and take x and y co-ordinate value from database
Draw graph using jsp without database connection
Draw graph using jsp without database connection  Draw graph using jsp code without database connection
how to fetch data from mysql database table and draw a bar chart on that data using in jsp
how to fetch data from mysql database table and draw a bar chart on that data using in jsp  how to create bar chart fetch data from mysql database using in jsp.please give me a right code. yhanks in advance
How can i draw a line using java swings
How can i draw a line using java swings  Sir my program contains different components i am using JFrame. I want to draw a straight line between components(Jtextfeilds, Jlabels).So could you help me for it. Thank You
How can i draw a line using java swings
How can i draw a line using java swings  Sir my program contains different components i am using JFrame. I want to draw a straight line between components(Jtextfeilds, Jlabels).So could you help me for it. Thank You
how to draw network with nodes - Java Beginners
how to draw network with nodes  how can i draw a network graph (game theory) with 3 nodes and each node display some information
Java draw triangle draw method?
Java draw triangle draw method?  hi how would i construct the draw method for an triangle using the 'public void draw (graphics g ) method? im... a rectangle and this works for a rectangle: public void draw(Graphics g
how to draw network(lines and nodes) in java - Applet
how to draw network(lines and nodes) in java  Hi, Iam doing my MSC project. I want to know, how can we draw a network(with lines and nodes, any number of lines and nodes... say 5). I also want to know how can we draw a graph
how to draw a table on jframe in java - Java Beginners
how to draw a table on jframe in java  how to draw a table on jframe in java?  Hi friend, import java.awt.*; import...://www.roseindia.net/java/example/java/swing/ Thanks
how can i draw a table using applet or swings - Java Beginners
how can i draw a table using applet or swings  Hi RoseIndia, Actually, I was trying for creating a table using applet or swings.......... My task is create a table and enter the integer values during run time......I have
How to draw pie chart in J2ME
How to draw pie chart in J2ME  Hi, I'm developing a program using J2ME and I want to draw a pie chart but it seems J2ME language hasn't available chart component like JFreeChart in Java! could any one help me how can I draw a pie
how to draw a network with nodes and lines connecting them - Java Beginners
how to draw a network with nodes and lines connecting them   HI, can anyone tell me, how to draw a network with nodes connected with lines in java....( say for 3 nodes). Actually iam doing a project. In that, i need to show
Dynamic Line draw in JSp
Dynamic Line draw in JSp  In my application. I have one source... "next" button it should give me multiple lines drw from one source to respective multiple target. And each line should have dynamically link of other jsp page
How to draw a house, draw a house, a house
How to draw a house       Use this example to draw a house in the photoshop, it has been... by using Pen tool. Choose this "decdb2" color and make points
How to draw globe, draw globe, globe
How to draw globe      .... New File: Start by taking a new document. Draw Circle: Choose any color and Ellipse Tool (U key) to draw a circle as given below. World Map: Capture a world map
How to draw to graph in Ms Excel from the data which is sent from an java application....?
How to draw to graph in Ms Excel from the data which is sent from an java application....?  How to draw to graph in Ms Excel from the data which is sent from an java application
How to draw a wall, draw a wall, a wall
How to draw a wall       Now we are going to teach you to draw a real wall by the photoshop, it is very easy by my this example. Select color: First take a new document and choose
Lottery Draw - Java Beginners
Java lottery program  Please send me an example for the Lottery Draw application in Java.Thanks in advance
Draw bufferimage in jpanel using netbeans
Draw bufferimage in jpanel using netbeans  please i need urgent help. i have form which contains some fields generated in netbeans. how can i draw bufferimage in Jpanel that is inside the form. thanks
how to draw multilple circles in a circular form and connect them with lines - Java Beginners
how to draw multilple circles in a circular form and connect them with lines  Hi, Can anyone explains me , how to draw multiple circles using a single applet or swings in a circular form and connect them with lines. It should
Draw a diamond - Java Beginners
Draw a diamond  I want to draw a diamond shapein java using (*) in 9 lines. Here is the code import java.util.*; public class Diamond { static... the number of star lines and number of blanks"); noOfstarlines=console.nextInt
How to draw a bullet spot on the car, draw a bullet spot on the car, draw a bullet spot
How to draw a bullet spot on the car       This example has a technique to draw a bullet spot... a car picture. Circle: Draw a circle with "5d6780" color
How to draw a soccer boll
How to draw a soccer boll Draw a soccer boll by using...; . Polygonal Shape: Draw a shape with Black color... and draw again a polygonal shape. Define Pattern: Convert this file
Draw String Using Canvas
Draw String Using Canvas       This example is used to draw string on different location which is shown in figure. The given code is used to show, how to draw string at different