
package web;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.io.PrintWriter;
import javax.imageio.ImageIO;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class ServletTest1 extends HttpServlet {
private int HEIGHT =25;
private int WIDTH=100;
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
BufferedImage im=new BufferedImage( WIDTH,HEIGHT,BufferedImage.TYPE_INT_RGB);
Graphics g = im.getGraphics();
setBackGround(g);
randomLine(g);
randomNum(g);
ImageIO.write(im, "jpg", response.getOutputStream());
}
private void randomLine(Graphics g) {
g.setColor(Color.RED);
g.drawRect(0, 0, WIDTH-1, HEIGHT-1);
g.setColor(Color.BLUE);
for(int i=0;i<4;i++){
int x1=(int) (Math.random()* WIDTH) ;
int x2=(int) (Math.random()* WIDTH ) ;
int y1=(int) (Math.random()*HEIGHT) ;
int y2=(int) (Math.random()*HEIGHT) ;