public void render() { Graphics g = screen.getGraphics(); // Drawing Things! sky.render(g); level.render( g, (int) sX, (int) sY, (pixel.width / Tile.tileSize) + 2, (pixel.height / Tile.tileSize) + 2); character.render(g); inventory.render(g); health.render(g); for (int i = 0; i < mob.toArray().length; i++) { mob.get(i).render(g); } g = getGraphics(); g.drawImage(screen, 0, 0, size.width, size.height, 0, 0, pixel.width, pixel.height, null); g.dispose(); }
public Image getScreenshot() { BufferedImage image = new BufferedImage(getWidth(), getHeight(), BufferedImage.TYPE_4BYTE_ABGR); Graphics g = image.getGraphics(); paint(g); g.dispose(); return image; }
/** This internal method begins a new line */ protected void newline() { charnum = 0; // Reset character number to 0 linenum++; // Increment line number if (linenum >= lines_per_page) { // If we've reached the end of the page page.dispose(); // send page to printer page = null; // but don't start a new page yet. } }
public void collect() { for (int i = 0; i < variable_list.size(); i++) { ((NslVariable) variable_list.elementAt(i)).collect(); } Graphics gr = getGraphics(); paint_partial(gr); gr.dispose(); }
@Override protected void paintTabBackground( Graphics g, int tabPlacement, int tabIndex, int x, int y, int w, int h, boolean isSelected) { g = g.create(); try { internalPaintTabBackground(g, tabPlacement, tabIndex, x, y, w, h, isSelected); } finally { g.dispose(); } }
/** * This paints the entire plot. It calls the draw methods of all the attached axis and data sets. * The order of drawing is - Axis first, data legends next, data last. * * @params g Graphics state. */ public void paint(Graphics g) { int i; Graphics lg = g.create(); Rectangle r = bounds(); /* The r.x and r.y returned from bounds is relative to the ** parents space so set them equal to zero. */ r.x = 0; r.y = 0; if (DefaultBackground == null) DefaultBackground = this.getBackground(); if (DataBackground == null) DataBackground = this.getBackground(); // System.out.println("Graph2D paint method called!"); if (!paintAll) return; r.x += borderLeft; r.y += borderTop; r.width -= borderLeft + borderRight; r.height -= borderBottom + borderTop; paintFirst(lg, r); if (!axis.isEmpty()) r = drawAxis(lg, r); else { if (clearAll) { Color c = g.getColor(); g.setColor(DataBackground); g.fillRect(r.x, r.y, r.width, r.height); g.setColor(c); } drawFrame(lg, r.x, r.y, r.width, r.height); } paintBeforeData(lg, r); if (!dataset.isEmpty()) { datarect.x = r.x; datarect.y = r.y; datarect.width = r.width; datarect.height = r.height; for (i = 0; i < dataset.size(); i++) { ((DataSet) dataset.elementAt(i)).draw_data(lg, r); } } paintLast(lg, r); lg.dispose(); }
/** end displaying message and force a graph repaint */ public void end() { super.stop(); g2d.clearAll = true; g2d.paintAll = true; if (lg != null) lg.dispose(); g2d.repaint(); }
/** * Paint a background for all groups and a round blue border and background when a cell is * selected. * * @param g the <tt>Graphics</tt> object used for painting */ @Override public void paintComponent(Graphics g) { super.paintComponent(g); g = g.create(); try { internalPaintComponent(g); } finally { g.dispose(); } }
public Line render(String text, Color c) { text = Translate.get(text); Coord sz = strsize(text); if (sz.x < 1) sz = sz.add(1, 0); BufferedImage img = TexI.mkbuf(sz); Graphics g = img.createGraphics(); if (aa) Utils.AA(g); g.setFont(font); g.setColor(c); FontMetrics m = g.getFontMetrics(); g.drawString(text, 0, m.getAscent()); g.dispose(); return (new Line(text, img, m)); }
/** Prints the drawing. */ public void print() { tool().deactivate(); PrintJob printJob = getToolkit().getPrintJob(this, "Print Drawing", null); if (printJob != null) { Graphics pg = printJob.getGraphics(); if (pg != null) { ((StandardDrawingView) view()).printAll(pg); pg.dispose(); // flush page } printJob.end(); } tool().activate(); }
/** Scales an image. To be used for tiles. Probably not the most efficient scaling method. */ public static Image scaleImage(Image orig, int scale) { Image result; if (scale != 1) { int width = orig.getWidth(null); int height = orig.getHeight(null); // Scale cropped image to proper size result = new BufferedImage(width * scale, height * scale, BufferedImage.TYPE_INT_ARGB); Graphics g = ((BufferedImage) result).createGraphics(); g.drawImage(orig, 0, 0, width * scale, height * scale, 0, 0, width - 1, height - 1, null); g.dispose(); } else { return orig; } return result; }
/** @{inheritDoc} */ @Override public void paintComponent(Graphics g) { super.paintComponent(g); g = g.create(); try { AntialiasingManager.activateAntialiasing(g); g.setColor(Color.DARK_GRAY); g.fillRoundRect(0, 0, this.getWidth(), this.getHeight(), 10, 10); } finally { g.dispose(); } }
private static Icon createColoredIcon(Color color) { Icon icon = icons_cache.get(color); if (icon != null) return icon; final BufferedImage image = GraphicsEnvironment.getLocalGraphicsEnvironment() .getDefaultScreenDevice() .getDefaultConfiguration() .createCompatibleImage(16, 16, Color.TRANSLUCENT); final Graphics g = image.getGraphics(); g.setColor(color); g.fillRect(0, 0, 16, 16); g.dispose(); icon = new ImageIcon(image); icons_cache.put(color, icon); return icon; }
/** * Paints a customized background. * * @param g the <tt>Graphics</tt> object through which we paint */ @Override protected void paintComponent(Graphics g) { super.paintComponent(g); g = g.create(); if (!(treeNode instanceof GroupNode) && !isSelected) return; AntialiasingManager.activateAntialiasing(g); Graphics2D g2 = (Graphics2D) g; try { internalPaintComponent(g2); } finally { g.dispose(); } }
public void paint(Graphics g) { Dimension osize = getSize(); if ((buffer == null) || (osize.height != buffer.getHeight(null)) || (osize.width != buffer.getWidth(null))) { if (buffer != null) { buffer.flush(); } buffer = createImage(osize.width, osize.height); } Graphics gc = buffer.getGraphics(); drawAll(gc); g.drawImage(buffer, 0, 0, this); gc.dispose(); }
public static java.awt.image.BufferedImage loadBufferedImageFromResources( Component c, String filename) { try { Misc m = new Misc(); java.awt.Image img = loadImageFromResources(filename); MediaTracker mt = new MediaTracker(c); mt.addImage(img, 0); mt.waitForID(0); int width = img.getWidth(null); int height = img.getHeight(null); BufferedImage bi = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); Graphics gg = bi.getGraphics(); gg.drawImage(img, 0, 0, null); gg.dispose(); return bi; } catch (Exception ex) { System.out.println(ex.toString()); } return null; }
public void actionPerformed(ActionEvent e) { PrintJob pjob = getToolkit().getPrintJob(textViewerFrame, "Printing Nslm", null); if (pjob != null) { Graphics pg = pjob.getGraphics(); if (pg != null) { // todo: this should print from // the file not from the screen. // if (editor1!=null) { // editor1.print(pg); //print crashes, must use printAll // } // if (scroller1!=null) { // scroller1.printAll(pg); //is clipping on left // } if (scroller1 != null) { JViewport jvp = scroller1.getViewport(); jvp.printAll(pg); } pg.dispose(); } pjob.end(); } }
/** * Draw the icon at the specified location. Paints this component as an icon. * * @param c the component which can be used as observer * @param g the <tt>Graphics</tt> object used for painting * @param x the position on the X coordinate * @param y the position on the Y coordinate */ public void paintIcon(Component c, Graphics g, int x, int y) { g = g.create(); try { Graphics2D g2 = (Graphics2D) g; AntialiasingManager.activateAntialiasing(g2); g2.setColor(Color.WHITE); g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.8f)); g2.fillRoundRect(x, y, getIconWidth() - 1, getIconHeight() - 1, 10, 10); g2.setColor(Color.DARK_GRAY); g2.drawRoundRect(x, y, getIconWidth() - 1, getIconHeight() - 1, 10, 10); // Indent component content from the border. g2.translate(x + 5, y + 5); super.paint(g2); g2.translate(x, y); } finally { g.dispose(); } }
public void paint(Graphics g) { if (histogram != null) { if (os == null) { os = createImage(WIDTH, HEIGHT); osg = os.getGraphics(); osg.setColor(Color.white); osg.fillRect(0, 0, WIDTH, HEIGHT); osg.setColor(Color.gray); for (int i = 0; i < WIDTH; i++) { if (hColors != null) osg.setColor(hColors[i]); osg.drawLine(i, HEIGHT, i, HEIGHT - ((int) (HEIGHT * histogram[i]) / hmax) - 4); } osg.dispose(); } g.drawImage(os, 0, 0, this); } else { g.setColor(Color.white); g.fillRect(0, 0, WIDTH, HEIGHT); } g.setColor(Color.black); g.drawLine(0, HEIGHT - 4, 256, HEIGHT - 4); g.drawRect(0, 0, WIDTH, HEIGHT); g.drawRect((int) minHue, 1, (int) (maxHue - minHue), HEIGHT - 5); }
/** * Parse the text then draw it without any rotation. * * @param g Graphics context * @param x pixel position of the text * @param y pixel position of the text */ public void draw(Graphics g, int x, int y) { TextState ts; int xoffset = x; int yoffset = y; if (g == null || text == null) return; Graphics lg = g.create(); parseText(g); if (justification == CENTER) { xoffset = x - width / 2; } else if (justification == RIGHT) { xoffset = x - width; } if (background != null) { lg.setColor(background); lg.fillRect(xoffset, yoffset - ascent, width, height); lg.setColor(g.getColor()); } if (font != null) lg.setFont(font); if (color != null) lg.setColor(color); for (int i = 0; i < list.size(); i++) { ts = ((TextState) (list.elementAt(i))); if (ts.f != null) lg.setFont(ts.f); if (ts.s != null) lg.drawString(ts.toString(), ts.x + xoffset, ts.y + yoffset); } lg.dispose(); lg = null; }
/** * This is the close() method that all Writer subclasses must implement. Print the pending page * (if any) and terminate the PrintJob. */ public void close() { synchronized (this.lock) { if (page != null) page.dispose(); // Send page to the printer job.end(); // Terminate the job } }
/** * PAINT recall that paint() is called the first time the window needs to be drawn, or if * something damages the window, and in this case by RefreshScreenNow() */ public void paint(Graphics g) { super.paint(g); // first paint the panel normally // the following block of code is used // if this is the first time being drawn or if the window was resized // Otherwise we don't creat a new buffer Dimension d = getSize(); // if this is the first time being drawn or if the window was resized if ((doubleBufferImage == null) || (d.width != doubleBufferImageSize.width) || (d.height != doubleBufferImageSize.height)) { doubleBufferImage = createImage(d.width, d.height); doubleBufferImageSize = d; if (doubleBufferGraphic != null) { doubleBufferGraphic.dispose(); } doubleBufferGraphic = doubleBufferImage.getGraphics(); doubleBufferGraphic.setFont(getFont()); } doubleBufferGraphic.setColor(Color.white); doubleBufferGraphic.fillRect(0, 0, d.width, d.height); if ((fitToScreenAutomatically) || (screenIsEmpty)) { // if the user wants all the nodes on the screen, // or if these are the first nodes on the screen, // fit all nodes to the visible area FitToScreen(); } // draw things on the screen before any nodes or edges appear MainClass.displayManager.PaintUnderScreen(doubleBufferGraphic); // draw all the nodes DisplayManager.NodeInfo nodeDisplayInfo; int xCoord, yCoord, imageWidth, imageHeight; for (Enumeration nodes = MainClass.displayManager.GetNodeInfo(); nodes.hasMoreElements(); ) { nodeDisplayInfo = (DisplayManager.NodeInfo) nodes.nextElement(); // figure out where to put the node on the screen xCoord = ScaleNodeXCoordToScreenCoord( MainClass.locationAnalyzer.GetX(nodeDisplayInfo.GetNodeNumber())); yCoord = ScaleNodeYCoordToScreenCoord( MainClass.locationAnalyzer.GetY(nodeDisplayInfo.GetNodeNumber())); // if that spot is not on the visible area, don't draw it at all if ((xCoord > this.getSize().getWidth()) || (yCoord > this.getSize().getHeight())) { continue; } // MDW: Don't scale size of dots // imageWidth = (int)Math.max(20,xScale*nodeDisplayInfo.GetImageWidth()/100); // imageHeight = (int)Math.max(20,yScale*nodeDisplayInfo.GetImageHeight()/100); imageWidth = imageHeight = 20; MainClass.displayManager.PaintAllNodes( nodeDisplayInfo.GetNodeNumber(), xCoord - imageWidth / 2, yCoord - imageHeight / 2, xCoord + imageWidth / 2, yCoord + imageHeight / 2, doubleBufferGraphic); } // draw all the edges try { DisplayManager.EdgeInfo edgeDisplayInfo; for (Enumeration edges = MainClass.displayManager.GetEdgeInfo(); edges.hasMoreElements(); ) { edgeDisplayInfo = (DisplayManager.EdgeInfo) edges.nextElement(); // figure out the coordinates of the endpoints of the edge int x1 = ScaleNodeXCoordToScreenCoord( MainClass.locationAnalyzer.GetX(edgeDisplayInfo.GetSourceNodeNumber())); int y1 = ScaleNodeYCoordToScreenCoord( MainClass.locationAnalyzer.GetY(edgeDisplayInfo.GetSourceNodeNumber())); int x2 = ScaleNodeXCoordToScreenCoord( MainClass.locationAnalyzer.GetX(edgeDisplayInfo.GetDestinationNodeNumber())); int y2 = ScaleNodeYCoordToScreenCoord( MainClass.locationAnalyzer.GetY(edgeDisplayInfo.GetDestinationNodeNumber())); // edgeDisplayInfo.paint(doubleBufferGraphic); MainClass.displayManager.PaintAllEdges( edgeDisplayInfo.GetSourceNodeNumber(), edgeDisplayInfo.GetDestinationNodeNumber(), x1, y1, x2, y2, doubleBufferGraphic); } } catch (Exception ex) { ex.printStackTrace(); } // draw things over the entire display MainClass.displayManager.PaintOverScreen(doubleBufferGraphic); // Make everything that was drawn visible g.drawImage(doubleBufferImage, 0, 0, null); }
/*.................................................................................................................*/ public Object doCommand(String commandName, String arguments, CommandChecker checker) { Tree trt = treeDisplay.getTree(); MesquiteTree t = null; if (trt instanceof MesquiteTree) t = (MesquiteTree) trt; if (checker.compare( this.getClass(), "Adjust tool has touched branch", "[branch number][x coordinate touched][y coordinate touched][modifiers]", commandName, "touchedPositionAdjust")) { if (t == null) return null; MesquiteInteger io = new MesquiteInteger(0); int node = MesquiteInteger.fromString(arguments, io); int x = MesquiteInteger.fromString(arguments, io); int y = MesquiteInteger.fromString(arguments, io); String mod = ParseUtil.getRemaining(arguments, io); Point newOnLine = treeDisplay.getTreeDrawing().projectionOnLine(node, x, y); originalX = newOnLine.x; originalY = newOnLine.y; // lastX= newOnLine.x; // lastY = newOnLine.y; Graphics g = null; if (GraphicsUtil.useXORMode(null, false)) { g = treeDisplay.getGraphics(); g.setXORMode(Color.white); g.setColor(Color.red); } // double bX = treeDisplay.getTreeDrawing().lineBaseX[node]; // double bY = treeDisplay.getTreeDrawing().lineBaseY[node]; // Math.sqrt((originalY-bY)*(originalY-bY) + (originalX-bX)*(originalX-bX)); lastBL = tree.getBranchLength(node); double shortestAbove = MesquiteDouble.unassigned; for (int daughter = t.firstDaughterOfNode(node); t.nodeExists(daughter); daughter = t.nextSisterOfNode(daughter)) shortestAbove = MesquiteDouble.minimum(shortestAbove, tree.getBranchLength(daughter)); if (shortestAbove == MesquiteDouble.unassigned) upperLimit = MesquiteDouble.infinite; else if (MesquiteDouble.isCombinable(lastBL)) upperLimit = shortestAbove + lastBL; else upperLimit = shortestAbove + 1.0; int ibX = treeDisplay.getTreeDrawing().lineBaseX[node]; int ibY = treeDisplay.getTreeDrawing().lineBaseY[node]; lastX = treeDisplay.getTreeDrawing().lineTipX[node]; lastY = treeDisplay.getTreeDrawing().lineTipY[node]; if (GraphicsUtil.useXORMode(null, false)) { drawThickLine(g, ibX, ibY, lastX, lastY); for (int daughter = t.firstDaughterOfNode(node); t.nodeExists(daughter); daughter = t.nextSisterOfNode(daughter)) drawThickLine( g, treeDisplay.getTreeDrawing().lineTipX[daughter], treeDisplay.getTreeDrawing().lineTipY[daughter], lastX, lastY); g.fillOval( lastX - ovalRadius, lastY - ovalRadius, ovalRadius + ovalRadius, ovalRadius + ovalRadius); try { g.drawString(MesquiteDouble.toString(lastBL), lastX + 10, lastY); } catch (InternalError e) { // workaround for bug on windows java 1.7. } catch (Throwable e) { } lineOn = true; g.dispose(); } } else if (checker.compare( this.getClass(), "Adjust tool has been dropped", "[branch number][x coordinate dropped][y coordinate dropped]", commandName, "droppedPositionAdjust")) { if (t == null) return null; if (editorOn) return null; MesquiteInteger io = new MesquiteInteger(0); int node = MesquiteInteger.fromString(arguments, io); int x = MesquiteInteger.fromString(arguments, io); int y = MesquiteInteger.fromString(arguments, io); if (lineOn) { Point newOnLine = treeDisplay.getTreeDrawing().projectionOnLine(node, x, y); double bX = treeDisplay.getTreeDrawing().lineBaseX[node]; double bY = treeDisplay.getTreeDrawing().lineBaseY[node]; double tX = treeDisplay.getTreeDrawing().lineTipX[node]; double tY = treeDisplay.getTreeDrawing().lineTipY[node]; double lengthLine = Math.sqrt((originalY - bY) * (originalY - bY) + (originalX - bX) * (originalX - bX)); double bL; if (lengthLine != 0) { double extension = Math.sqrt( (newOnLine.y - bY) * (newOnLine.y - bY) + (newOnLine.x - bX) * (newOnLine.x - bX)) / lengthLine; if (t.getBranchLength(node) == 0 || t.branchLengthUnassigned(node)) bL = extension; else bL = t.getBranchLength(node) * extension; } else bL = 1; if (bL > upperLimit) bL = upperLimit; else if (bL < lowerLimit) bL = lowerLimit; double oldBL = t.getBranchLength(node); if (!MesquiteDouble.isCombinable(oldBL)) oldBL = 1.0; t.setBranchLength(node, bL, false); double difference = oldBL - t.getBranchLength(node); for (int daughter = t.firstDaughterOfNode(node); t.nodeExists(daughter); daughter = t.nextSisterOfNode(daughter)) if (MesquiteDouble.isCombinable(t.getBranchLength(daughter))) t.setBranchLength(daughter, t.getBranchLength(daughter) + difference, false); t.notifyListeners(this, new Notification(MesquiteListener.BRANCHLENGTHS_CHANGED)); Graphics g = treeDisplay.getGraphics(); g.setPaintMode(); g.dispose(); treeDisplay.pleaseUpdate(true); lineOn = false; } } else if (checker.compare( this.getClass(), "Adjust tool is being dragged", "[branch number][x coordinate][y coordinate]", commandName, "draggedPositionAdjust")) { if (t == null) return null; if (editorOn) return null; MesquiteInteger io = new MesquiteInteger(0); int node = MesquiteInteger.fromString(arguments, io); int x = MesquiteInteger.fromString(arguments, io); int y = MesquiteInteger.fromString(arguments, io); if (lineOn) { Point newOnLine = treeDisplay.getTreeDrawing().projectionOnLine(node, x, y); // WARNING": This shouldn't result in length increase if simple click and release with no // drag; must subtract original X, Y Graphics g = null; if (GraphicsUtil.useXORMode(null, false)) { g = treeDisplay.getGraphics(); g.setXORMode(Color.white); g.setColor(Color.red); } // g.fillOval(lastX-ovalRadius, lastY-ovalRadius, ovalRadius + ovalRadius, ovalRadius + // ovalRadius); // g.fillOval(newOnLine.x-ovalRadius, newOnLine.y -ovalRadius, ovalRadius + ovalRadius, // ovalRadius + ovalRadius); // g.drawLine(originalX, originalY, lastX, lastY); // g.drawLine(originalX, originalY, newOnLine.x, newOnLine.y); // if decreasing, & unassigned involved: push unassigned down and assign values to // unassigned above; if increasing, push unassigne up int ibX = treeDisplay.getTreeDrawing().lineBaseX[node]; int ibY = treeDisplay.getTreeDrawing().lineBaseY[node]; int itX = treeDisplay.getTreeDrawing().lineTipX[node]; int itY = treeDisplay.getTreeDrawing().lineTipY[node]; double bX = ibX; double bY = ibY; double tX = itX; double tY = itY; double lengthLine = Math.sqrt((originalY - bY) * (originalY - bY) + (originalX - bX) * (originalX - bX)); if (lengthLine != 0) { if (GraphicsUtil.useXORMode(null, false)) { if (MesquiteTrunk.isMacOSX() && MesquiteTrunk.getJavaVersionAsDouble() >= 1.5 && MesquiteTrunk.getJavaVersionAsDouble() < 1.6) // due to a JVM bug g.fillRect(lastX, lastY - 20, 100, 20); g.drawString(MesquiteDouble.toString(lastBL), lastX + 10, lastY); if (MesquiteTrunk.isMacOSX() && MesquiteTrunk.getJavaVersionAsDouble() >= 1.5 && MesquiteTrunk.getJavaVersionAsDouble() < 1.6) // due to a JVM bug g.fillRect(lastX, lastY - 20, 100, 20); } double extension = Math.sqrt( (newOnLine.y - bY) * (newOnLine.y - bY) + (newOnLine.x - bX) * (newOnLine.x - bX)) / lengthLine; double bL; if (t.getBranchLength(node) == 0 || t.branchLengthUnassigned(node)) bL = extension; else bL = t.getBranchLength(node) * extension; if (bL > upperLimit) { bL = upperLimit; if (t.getBranchLength(node) == 0 || t.branchLengthUnassigned(node)) extension = upperLimit; else extension = upperLimit / t.getBranchLength(node); } else if (bL < lowerLimit) { bL = lowerLimit; if (t.getBranchLength(node) == 0 || t.branchLengthUnassigned(node)) extension = lowerLimit; else extension = lowerLimit / t.getBranchLength(node); } lastBL = bL; if (GraphicsUtil.useXORMode(null, false)) { drawThickLine(g, ibX, ibY, lastX, lastY); for (int daughter = t.firstDaughterOfNode(node); t.nodeExists(daughter); daughter = t.nextSisterOfNode(daughter)) drawThickLine( g, treeDisplay.getTreeDrawing().lineTipX[daughter], treeDisplay.getTreeDrawing().lineTipY[daughter], lastX, lastY); g.fillOval( lastX - ovalRadius, lastY - ovalRadius, ovalRadius + ovalRadius, ovalRadius + ovalRadius); } int newX = ibX + (int) (extension * (tX - bX)); int newY = ibY + (int) (extension * (tY - bY)); if (GraphicsUtil.useXORMode(null, false)) { g.drawString(MesquiteDouble.toString(bL), newX + 10, newY); drawThickLine(g, ibX, ibY, newX, newY); for (int daughter = t.firstDaughterOfNode(node); t.nodeExists(daughter); daughter = t.nextSisterOfNode(daughter)) drawThickLine( g, treeDisplay.getTreeDrawing().lineTipX[daughter], treeDisplay.getTreeDrawing().lineTipY[daughter], newX, newY); g.fillOval( newX - ovalRadius, newY - ovalRadius, ovalRadius + ovalRadius, ovalRadius + ovalRadius); } lastX = newX; lastY = newY; } // lastX= newOnLine.x; // lastY = newOnLine.y; } } return null; }
public void _jspService(HttpServletRequest request, HttpServletResponse response) throws java.io.IOException, ServletException { PageContext pageContext = null; HttpSession session = null; ServletContext application = null; ServletConfig config = null; JspWriter out = null; Object page = this; JspWriter _jspx_out = null; PageContext _jspx_page_context = null; try { response.setContentType("image/jpeg"); pageContext = _jspxFactory.getPageContext( this, request, response, "/myhtml/errorpage/erroe.jsp", true, 8192, true); _jspx_page_context = pageContext; application = pageContext.getServletContext(); config = pageContext.getServletConfig(); session = pageContext.getSession(); out = pageContext.getOut(); _jspx_out = out; out.write("\r\n"); out.write("\r\n"); out.write('\r'); out.write('\n'); // 设置页é¢ä¸ç¼å response.setHeader("Pragma", "No-cache"); response.setHeader("Cache-Control", "no-cache"); response.setDateHeader("Expires", 0); // å¨å åä¸å建å¾è±¡ int width = 60, height = 20; BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); // è·åå¾å½¢ä¸ä¸æ Graphics g = image.getGraphics(); // çæéæºç±» Random random = new Random(); // 设å®èæ¯è² g.setColor(getRandColor(200, 250)); g.fillRect(0, 0, width, height); // 设å®åä½ g.setFont(new Font("Times New Roman", Font.PLAIN, 18)); // ç»è¾¹æ¡ // g.setColor(new Color()); // g.drawRect(0,0,width-1,height-1); // éæºäº§ç155æ¡å¹²æ°çº¿ï¼ä½¿å¾è±¡ä¸ç认è¯ç ä¸æè¢«å ¶å®ç¨åºæ¢æµå° g.setColor(getRandColor(160, 200)); for (int i = 0; i < 155; i++) { int x = random.nextInt(width); int y = random.nextInt(height); int xl = random.nextInt(12); int yl = random.nextInt(12); g.drawLine(x, y, x + xl, y + yl); } // åéæºäº§çç认è¯ç (4ä½æ°å) String sRand = ""; for (int i = 0; i < 4; i++) { String rand = String.valueOf(random.nextInt(10)); sRand += rand; // å°è®¤è¯ç æ¾ç¤ºå°å¾è±¡ä¸ g.setColor( new Color( 20 + random.nextInt(110), 20 + random.nextInt(110), 20 + random.nextInt(110))); // è°ç¨å½æ°åºæ¥çé¢è²ç¸åï¼å¯è½æ¯å // 为ç§å太æ¥è¿ï¼æ以åªè½ç´æ¥çæ g.drawString(rand, 13 * i + 6, 16); } // å°è®¤è¯ç åå ¥SESSION session.setAttribute("rand", sRand); // å¾è±¡çæ g.dispose(); // è¾åºå¾è±¡å°é¡µé¢ ImageIO.write(image, "JPEG", response.getOutputStream()); out.clear(); out = pageContext.pushBody(); } catch (Throwable t) { if (!(t instanceof SkipPageException)) { out = _jspx_out; if (out != null && out.getBufferSize() != 0) try { out.clearBuffer(); } catch (java.io.IOException e) { } if (_jspx_page_context != null) _jspx_page_context.handlePageException(t); else log(t.getMessage(), t); } } finally { _jspxFactory.releasePageContext(_jspx_page_context); } }