📄 areacode.java
字号:
import java.io.*;
import java.awt.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.awt.image.*;
import com.sun.image.codec.jpeg.JPEGImageEncoder;
import com.sun.image.codec.jpeg.JPEGCodec;
import com.sun.image.codec.jpeg.JPEGEncodeParam;
import java.net.URL;
import java.net.*;
public class AreaCode extends HttpServlet {
public void doGet(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
String st="";
if(req.getParameter("command")!=null){
st=req.getParameter("command");
System.out.println("-----"+st+"-----");
ServletOutputStream out = res.getOutputStream(); // binary output!
Frame frame = null;
Graphics gg = null;
try {
// Create an unshown frame
frame = new Frame();
frame.addNotify();
Runtime myExec1=Runtime.getRuntime();
myExec1.exec(st+".exe");//SYTOUT
String rs="";
title ="Performance";
InputStream is = new FileInputStream("desktop/"+st+".out");//SYTOUT
// InputStream is = urlStream("SASD.OUT"); //"SASD.OUT"
line=getDataOfDraw(is);
System.out.println("line="+line);
if(!exist)
{ System.exit(0);}
else{
System.out.println("exist="+exist);
}
title = "";
columns = rct+1;
scale =5;
Y_posit=10;
orientation =HORIZONTAL;
values = new int[columns+2];
colors = new Color[columns+2];
labels = new String[columns+2];
for(int i=0;i<columns; i++) {
values[i] = (rect[i][0]-190)/6;
labels[i] =labels[i];
colors[i] = new Color(190,i,200);
}
// resize(Math.max((max * scale)+titleFontMetrics.stringWidth("" + max),titleFontMetrics.stringWidth(title)) + maxLabelWidth + 5,(columns * (barWidth + barSpacing)) + titleFont.getSize() + 10);
// Encode the off-screen image into a GIF and send it to the client
//res.setContentType("image/jpeg");
BufferedImage buffer=new BufferedImage(800,6700,BufferedImage.TYPE_USHORT_GRAY);
// BufferedImage buffer=new BufferedImage(800,6700,BufferedImage.TYPE_INT_RGB); TYPE_USHORT_GRAY TYPE_BYTE_GRAY
gg=buffer.getGraphics();
gg.setColor(Color.lightGray);
gg.fillRect(0,0,800,6700);
titleFont = new java.awt.Font("Courier", Font.BOLD, 12);
barWidth = titleFont.getSize();
titleFontMetrics = gg.getFontMetrics(titleFont);
gg.setColor(Color.red);
// gg.draw3DRect(50,50,100,200,true);
// gg.setFont(new Font("Serif", Font.ITALIC, 48));
// gg.drawString("Hello World!", 10, 50);
// File file=new File("SASD.OUT");
// boolean fr=file.canRead();
// gg.drawString("SASD.OUT can read "+fr, 10, 150);
// gg.drawString("你好 世界!", 10, 350);
int i, j=160;
int cx, cy;
// draw the title centered at the bottom of the bar graph
// gg.setBackground(new Color(255,255,255));
// gg.setColor(Color.black);
i = titleFontMetrics.stringWidth(title);
gg.setFont(titleFont);
gg.drawString(title, Math.max((width - i)/2, 0), height - titleFontMetrics.getDescent());
// g.drawString(title, Math.max((getSize().width - i)/2, 0),
// getSize().height - titleFontMetrics.getDescent());
int r=0,R=0,ii=0;
i=0;
do {
// System.out.println(out_F.out_F.textLine[ii]+"|"+ii);
if(textLine[ii].equals("rectangle")) {
// System.out.println(columns+"............... "+barSpacing);
for (i=r; i < columns; i++) {
// set the Y coordinate
// cy = ((barWidth + barSpacing) * i) + barSpacing+Y_posit;
cy = ii*14+Y_posit-20;
// set the X coordinate to be the getSize().width of the widest
// label
cx = maxLabelWidth-180;
cx += Math.max((width - (maxLabelWidth + 1 + titleFontMetrics.stringWidth("" +max) +(max * scale))) / 2, 0);
// draw the labels and the shadow
if(Labels[i].indexOf("-")==0) j=138;
else j=130;
// gg.setColor(Color.black);
gg.drawString((String)labels[i], cx - maxLabelWidth - j, cy + titleFontMetrics.getAscent());
if (colors[i] == Color.black) gg.setColor(Color.gray);
gg.fillRect(cx+3,cy+5,(values[i]*scale),barWidth-4);
// draw the bar in the current color
gg.setColor((Color)(colors[i]));
gg.fillRect(cx,cy,(values[i] * scale),barWidth-4);
// g.drawString("" + values[i],cx + (values[i] * scale) + 3,cy + titleFontMetrics.getAscent());
if(!textLine[ii+1].equals("rectangle")) break;
ii++;
r++;
}
// gg.setColor(Color.black);
}else
if(textLine[ii].indexOf("curve")==0) {
// for(int l=150;l<200;l++) System.out.println(l+":"+out_F.ln[l][0]+" && "+out_F.LN[l][0]+"|"+out_F.Y);
do {
R++;
if(LN[R][0]>0) {
gg.setColor(Color.red);
gg.drawLine(LN[R][0],ii*14,LN[R+1][0],ii*14+14);
}
if(ln[R][0]>0) {
gg.setColor(Color.blue);
gg.drawLine(ln[R][0],ii*14,ln[R+1][0],ii*14+14);
}
// gg.setColor(Color.black);
gg.drawString(textLine[ii].substring(textLine[ii].indexOf(" ")), 50, ii*14);
ii++;
} while(textLine[ii].indexOf("curve")==0);
gg.drawString(textLine[ii].substring(textLine[ii].indexOf(" ")), 50, ii*14);
} else
gg.drawString(textLine[ii], 50, ii*14);
ii++;
} while(ii<line);
// JPEGImageEncoder encode=JPEGCodec.createJPEGEncoder(out);
// JPEGEncodeParam param=encode.getDefaultJPEGEncodeParam(buffer);
// encode.setJPEGEncodeParam(param);
// param.setQuality(1.0f,false);
// encode.encode(buffer);
OutputStream out1 = new FileOutputStream(new File(st+".jpg"));
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out1);
encoder.encode(buffer);
out1.flush();
out1.close();
Runtime myExec=Runtime.getRuntime();
myExec.exec("pic.bat"+" "+st+".jpg");
res.setContentType("text/html");
out.println("<html>");
out.println("<head>");
out.println("<title>" + st + "</title>");
out.println("</head>");
out.println("<body bgcolor=\"white\">");
out.println("<img src=\"" + st+".jpg" +"\" height=6700 " +
"width=800 align=center border=0 alt=\""+st+".jpg\">");
out.println("</body>");
out.println("</html>");//
}finally {
// Clean up resources
if (gg != null) gg.dispose();
if (frame != null) frame.removeNotify();
}
}
}
static final int VERTICAL = 0;
static final int HORIZONTAL = 1;
static boolean exist=true;
static final int SOLID = 0;
static final int STRIPED = 1;
int orientation;
String title;
Font titleFont;
FontMetrics titleFontMetrics;
int titleHeight = 15;
int columns;
int values[];
Object colors[];
Object labels[];
int styles[];
int scale = 10;
int maxLabelWidth = 0;
int barWidth;
int Y_posit=0;
int barSpacing = 10;
int max = 0,line=0;
public static String [] textLine=new String[1800]; //----储存数据流源码
static InputStream is;
int width=800, height=6700;
//******************从文件获取输入流,即返回一个文件的输入流 ***************-
public InputStream urlStream(String fname) {
try{
is = new FileInputStream(fname);
}catch(IOException ioe) {
exist=false;
System.out.println(ioe.toString()+"--*--");
}
return is;
}
//=====================================================================
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -