package com.hbsoft.servlet;import java.awt.Color;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Random;import javax.imageio.ImageIO;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;public class SecondServlet extends HttpServlet { public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException { this.doPost(request, response);
} public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException { response.setHeader("pragma","no-cache");
response.setHeader("cache-control","no-cache");
response.setHeader("expires","0");
response.setContentType("image/jpeg");
int width = 650;
int height = 520;
int StepX = 40;
int StepY = 40;
BufferedImage image = new BufferedImage(width,height,BufferedImage.TYPE_INT_RGB);
Graphics g = image.getGraphics();
g.setColor(Color.pink);
g.fillRect(0,0,width,height);
g.setColor(Color.blue);
//画出虚拟X轴并添加虚拟Y轴的左箭头和右箭头
g.drawLine(getConversionX(0),getConversionY(0),getConversionX(0),getConversionY(440));
g.drawLine(getConversionX(0),getConversionY(440),getConversionX(-5),getConversionY(435));
g.drawLine(getConversionX(0),getConversionY(440),getConversionX(5),getConversionY(435));
//画出虚拟Y轴并添加虚拟X轴的左箭头和右箭头
g.drawLine(getConversionX(0),getConversionY(0),getConversionX(500),getConversionY(0));
g.drawLine(getConversionX(500),getConversionY(0), getConversionX(495),getConversionY(5));
g.drawLine(getConversionX(500),getConversionY(0), getConversionX(495),getConversionY(-5));
int m = 0;
int n = 0;
int month = 0;
int money = 0;
int mm = StepX;
int random = 0;
boolean Judge = false;
int[] cc = new int[]{new Random().nextInt(450),new Random().nextInt(450)
,new Random().nextInt(450),new Random().nextInt(450)
,new Random().nextInt(450),new Random().nextInt(450)
,new Random().nextInt(450),new Random().nextInt(450)
,new Random().nextInt(450),new Random().nextInt(450)
,new Random().nextInt(450),new Random().nextInt(450)
,new Random().nextInt(450)};
for(int x = 0;x < 12;x ++){
m = m + StepY;
n = n + StepX;
money = money + 1;
g.drawString(money + "万亿元",getConversionX(-60),getConversionY(m-6));
g.drawLine(getConversionX(0), getConversionY(m),getConversionX(-5),getConversionY(m));
g.drawLine(getConversionX(n), getConversionY(0),getConversionX(n),getConversionY(5));
month = month + 1;
g.drawString(month + "月",getConversionX(n-15),getConversionY(-20));
if(Judge){
if(x!=11){
g.drawLine(getConversionX(mm), getConversionY(cc[x]),getConversionX(mm+StepX),getConversionY(cc[x+1]));
mm = mm + StepX;
}
}else{
if(x!=11){
random = cc[x];
g.drawRect(getConversionX(mm),getConversionY(random),10,450-getConversionY(random));
g.setColor(Color.yellow);
g.fillRect(getConversionX(mm),getConversionY(random),10,450-getConversionY(random));
mm = mm + StepX;
}
}
}
HttpSession session = request.getSession();
session.setAttribute("hand","");
ImageIO.write(image, "JPEG",response.getOutputStream());
}
public int getConversionX(int x1){
int x = 100;
int xx = x + x1;
return xx;
}
public int getConversionY(int y1){
int y = 450;
int yy = y - y1;
return yy;
}
}