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)

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)   ...); // Get drawing context Graphics g = image.getGraphics(); // Fill background
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 graph using jsp without database connection
Draw graph using jsp without database connection  Draw graph using jsp code without database connection
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
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
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
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
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
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
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 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
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 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 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
A Java Program by using JSP
A Java Program by using JSP  how to draw lines by using JSP plz show me the solution by using program
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 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... and make points by using Pen tool.ADS_TO_REPLACE_2 Choose this "decdb2
How to draw globe, draw globe, globe
How to draw globe      .... New File: Start by taking a new document.ADS_TO_REPLACE_1 Draw Circle: Choose any color and Ellipse Tool (U key) to draw a circle as given below. World Map
Lottery Draw - Java Beginners
Java lottery program  Please send me an example for the Lottery Draw application in Java.Thanks in advance
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
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 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 create using jsp
how to create using jsp  code 1: <%@ page language="java...;/body> </html> code 2: <%@ page language="java...;%@ page language="java" contentType="text/html; charset=ISO-8859-1
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
How to draw a soccer boll
How to draw a soccer boll Draw a soccer boll by using...; . ADS_TO_REPLACE_1 Polygonal Shape: Draw a shape with Black... to white and draw again a polygonal shape.ADS_TO_REPLACE_2 Define
How to draw a television
How to draw a television Try to draw a television... Shape: First draw a Rectangle shape with black color by using Rectangle tool (U... and rounded rectangle tool (U key) to draw a rounded rectangle shape.ADS_TO_REPLACE_5
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.ADS_TO_REPLACE_1 Circle: Draw a circle with "5d6780"
Draw a Triangle using a Line2D
Draw a Triangle using a Line2D       This section illustrates you how to draw a triangle using a Line2D. To draw a triangle, we are using Line2D class of package java.awt.geom.
Draw Statistical chart in jsp
Draw Statistical chart in jsp       This section illustrates you how to draw statistical chart in jsp by getting values from database.. To draw a bar chart, we have
Draw An Arc in Graphics
Draw An Arc in Graphics       In this section, you will learn how to draw an arc in Graphics. An arc of a circle is a segment of the circumference of the circle. To draw an arc
Write a Java applet to draw cylinder and pentagon shapes.
Write a Java applet to draw cylinder and pentagon shapes.  Write a Java applet to draw cylinder and pentagon shapes
Draw a line in a JPanel with button click in Java
Draw a line in a JPanel with button click in Java  Draw a line in a JPanel with button click in Java
How to draw a web button, draw a web button, web button
How to draw a web button       Be ready to learn a simple technique to draw a web button, if you... like.ADS_TO_REPLACE_1 Draw a circle: Choose Ellipse tool (U key) and drag a circle
How to draw a circle bucket, draw a circle bucket, circle bucket
How to draw a circle bucket       This example has a simple way to learn easily to make a circle shape.... ADS_TO_REPLACE_2 Draw Circle: Now draw a circle inside the big circle with any
tree using jsp code
tree using jsp code  i want to draw a tree structure of a family hierarchy using jsp code
How to export data from jsp to excel sheet by using java
How to export data from jsp to excel sheet by using java   How to export data from jsp to excel sheet by using java
How to show database values into graph using jsp?
How to show database values into graph using jsp?  How to show database values into graph using jsp
How to show database values into graph using jsp?
How to show database values into graph using jsp?  How to show database values into graph using jsp
how to upload and download images using buttons in jsp?
how to upload and download images using buttons in jsp?  how to upload and download images using buttons in jsp
How to upload files to server using JSP/Servlet?
How to upload files to server using JSP/Servlet?  How to upload files to server using JSP/Servlet
thanks deepak for guiding me to draw graphs using org.jfree - Java Beginners
thanks deepak for guiding me to draw graphs using org.jfree  Hi deepak, thanks deepak....... i got the graphs using org.jfree.......... as u said, i set the class path............ thanks mate
four rectangle/image of the shape of the button.then Draw these on some x and y co-ordinated in j2me then how to draw ?
four rectangle/image of the shape of the button.then Draw these on some x and y co-ordinated in j2me then how to draw ?  hi, i have button use.... then how to draw in j2me eclipse
How to upload file using JSP?
How to upload file using JSP?   Hi all, I m the beginner in JSP, I want to upload file on server in specific folder.   1)page.jsp: <%@ page language="java" %> <HTML> <HEAD><TITLE>Display

Ads