Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa JSP-Servlet how to draw lines,circles, rectangles on JSP (using Java Graphics)

Have Programming Question? Ask it here!
 
 
 


Anuj Kumar
how to draw lines,circles, rectangles on JSP (using Java Graphics)
2 Answer(s)      3 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
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 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
Draw graph using jsp without database connection
Draw graph using jsp without database connection  Draw graph using jsp code without database connection
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 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
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
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
How to draw a circle bucket, draw a circle bucket, circle bucket
How to draw a circle bucket     ... style: Go to Layer menu > Layer style > Bevel and emboss. Draw Circle: Now draw a circle inside the big circle with any color as you like.  
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...; color and rounded rectangle tool (U key) to draw a rounded rectangle shape
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.... Draw a circle: Choose Ellipse tool (U key) and drag a circle with "
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
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.
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
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
Java Swing: Draw rectangle on mouse click
Java Swing: Draw rectangle on mouse click In this tutorial, you will learn how to draw a rectangle on mouse click. Sometimes, there is a need of mouse clicks in swing applications instead of buttons. To add this mouse interaction, Java
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
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
how to drag top most images which is draw on applet.
how to drag top most images which is draw on applet.  Please help me, I have draw 83 images one by one from g.drawImages(,,,,); now I want to drag last image from 83 images and drop it suitable place, Now please help me , how can
Draw Line in J2me
Draw Line in J2me       In this example we are going to show you how to draw a line using J2ME. Please... and class to draw a line.  Basically in J2ME, Canvas class is used to draw
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
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
Draw Pie Chart
Draw Pie Chart       This Java Pie Chart example is going to show you how to draw Pie Charts in Java. This Java Pie Chart example is drawing a pie chart to show
Draw Line
Draw Line  sir i want to draw a moving line in j2me.That line should also show arrow in moving direction. How can we do so
how can i draw line between two panel contaning circle and line between their center?
how can i draw line between two panel contaning circle and line between their center?   how can i draw line between two panel contaning circle and line between their center
How to display data in jsp from dao using java beans?
How to display data in jsp from dao using java beans?  Hi I need to display data in jsp pulling from dao using java beans, Please can anyone give me the sample application with above topics. Any help would be highly appreciated
 

 

 

DMCA.com