List of usage examples for java.awt Graphics drawString
public abstract void drawString(AttributedCharacterIterator iterator, int x, int y);
From source file:com.klwork.common.utils.WebUtils.java
/** * ???//from www . j av a 2 s . c o m * @param request * @param response */ public static void VerificationCode(HttpServletRequest request, HttpServletResponse response) throws Exception { 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); } String base = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQUSTUVWXYZ0123456789"; // ????(4?) String sRand = ""; for (int i = 0; i < 4; i++) { int start = random.nextInt(base.length()); String rand = base.substring(start, start + 1); sRand = sRand.concat(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 request.getSession().setAttribute("entrymrand", sRand); // g.dispose(); OutputStream out = response.getOutputStream(); // ? ImageIO.write(image, "JPEG", out); out.flush(); out.close(); }
From source file:org.deegree.ogcwebservices.wms.dataaccess.ID2PInterpolation.java
private void writeErrorMessage() { Graphics g = image.getGraphics(); g.setColor(Color.WHITE);//from w w w. j a v a2 s. c om g.fillRect(0, 0, getMap.getWidth(), getMap.getHeight()); g.setColor(Color.RED); g.drawString("not enough values for interpolation available", 10, 50); g.dispose(); }
From source file:TextBox3D.java
public synchronized void paint(Graphics g) { FontMetrics fm = g.getFontMetrics(); Dimension size = getSize();/*from w w w . j a v a2 s .co m*/ int x = (size.width - fm.stringWidth(text)) / 2; int y = (size.height - fm.getHeight()) / 2; g.setColor(SystemColor.control); g.fillRect(0, 0, size.width, size.height); g.setColor(SystemColor.controlShadow); g.drawLine(0, 0, 0, size.height - 1); g.drawLine(0, 0, size.width - 1, 0); g.setColor(SystemColor.controlDkShadow); g.drawLine(0, size.height - 1, size.width - 1, size.height - 1); g.drawLine(size.width - 1, 0, size.width - 1, size.height - 1); g.setColor(SystemColor.controlText); g.drawString(text, x, y); }
From source file:org.esa.nest.dat.views.polarview.PolarCanvas.java
private void drawAxisLabels(Graphics graphics) { final int x = 20; final int y = origin.y; final int d = 50; graphics.setColor(Color.black); final int y2 = y - d; graphics.drawLine(x, y, x, y - d);//from ww w. jav a 2s .c o m graphics.drawLine(x, y2, x - 5, y2 + 5); graphics.drawLine(x, y2, x + 5, y2 + 5); graphics.drawString(axisLabel1, x - 15, y2 - 10); final int x2 = x + d; graphics.drawLine(x, y, x2, y); graphics.drawLine(x2, y, x2 - 5, y - 5); graphics.drawLine(x2, y, x2 - 5, y + 5); graphics.drawString(axisLabel2, x2 - 10, y + 20); }
From source file:org.esa.s1tbx.ocean.toolviews.polarview.polarplot.PolarCanvas.java
private void drawAxisLabels(Graphics graphics) { final int x = 20; final int y = origin.y + 50; final int d = 50; graphics.setColor(Color.black); final int y2 = y - d; graphics.drawLine(x, y, x, y - d);//w w w . ja v a2 s . c o m graphics.drawLine(x, y2, x - 5, y2 + 5); graphics.drawLine(x, y2, x + 5, y2 + 5); graphics.drawString(axisLabel1, x - 15, y2 - 10); final int x2 = x + d; graphics.drawLine(x, y, x2, y); graphics.drawLine(x2, y, x2 - 5, y - 5); graphics.drawLine(x2, y, x2 - 5, y + 5); graphics.drawString(axisLabel2, x2 - 10, y + 20); }
From source file:layout.BLDComponent.java
public void paint(Graphics g) { int width = getWidth(); int height = getHeight(); float alignmentX = getAlignmentX(); g.setColor(normalHue);// w ww . ja v a2s .c om g.fill3DRect(0, 0, width, height, true); /* Draw a vertical white line at the alignment point.*/ // XXX: This code is probably not the best. g.setColor(Color.white); int x = (int) (alignmentX * (float) width) - 1; g.drawLine(x, 0, x, height - 1); /* Say what the alignment point is. */ g.setColor(Color.black); g.drawString(Float.toString(alignmentX), 3, height - 3); if (printSize) { System.out.println("BLDComponent " + name + ": size is " + width + "x" + height + "; preferred size is " + getPreferredSize().width + "x" + getPreferredSize().height); } }
From source file:FontPanel.java
public void paintComponent(Graphics g) { super.paintComponent(g); Font f = new Font("SansSerif", Font.BOLD, 14); Font fi = new Font("SansSerif", Font.BOLD + Font.ITALIC, 14); FontMetrics fm = g.getFontMetrics(f); FontMetrics fim = g.getFontMetrics(fi); String s1 = "Java "; String s2 = "Source and Support"; String s3 = " at www.java2s.com"; int width1 = fm.stringWidth(s1); int width2 = fim.stringWidth(s2); int width3 = fm.stringWidth(s3); Dimension d = getSize();/*w ww.j a v a 2s . c o m*/ int cx = (d.width - width1 - width2 - width3) / 2; int cy = (d.height - fm.getHeight()) / 2 + fm.getAscent(); g.setFont(f); g.drawString(s1, cx, cy); cx += width1; g.setFont(fi); g.drawString(s2, cx, cy); cx += width2; g.setFont(f); g.drawString(s3, cx, cy); }
From source file:PlatformTest.java
private Shape3D createLabel(String szText, float x, float y, float z) { BufferedImage bufferedImage = new BufferedImage(25, 14, BufferedImage.TYPE_INT_RGB); Graphics g = bufferedImage.getGraphics(); g.setColor(Color.white);// www .j a v a 2 s. c o m g.drawString(szText, 2, 12); ImageComponent2D imageComponent2D = new ImageComponent2D(ImageComponent2D.FORMAT_RGB, bufferedImage); // create the Raster for the image javax.media.j3d.Raster renderRaster = new javax.media.j3d.Raster(new Point3f(x, y, z), javax.media.j3d.Raster.RASTER_COLOR, 0, 0, bufferedImage.getWidth(), bufferedImage.getHeight(), imageComponent2D, null); return new Shape3D(renderRaster); }
From source file:ScaleTest_2008.java
/** * Scale the image to several smaller sizes using each of the approaches * and time each series of operations. The times are output into the * application window for each row that they represent. *//*from www . ja va 2 s .c o m*/ protected void paintComponent(Graphics g) { if (!originalImagePainted) { paintOriginalImage(); } long startTime, endTime, totalTime; int xLoc, yLoc; // Draw scaled versions with nearest neighbor xLoc = 5; yLoc = 20; startTime = System.nanoTime(); drawImage(g, yLoc, false); endTime = System.nanoTime(); totalTime = (endTime - startTime) / 1000000; g.drawString("NEAREST ", xLoc, yLoc + (FULL_SIZE / 2)); g.drawString(Long.toString(totalTime) + " ms", xLoc, yLoc + (FULL_SIZE / 2) + 15); System.out.println("NEAREST: " + (endTime - startTime) / 1000000); // BILINEAR yLoc += FULL_SIZE + PADDING; ((Graphics2D) g).setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR); startTime = System.nanoTime(); drawImage(g, yLoc, false); endTime = System.nanoTime(); totalTime = (endTime - startTime) / 1000000; g.drawString("BILINEAR ", xLoc, yLoc + (FULL_SIZE / 2)); g.drawString(Long.toString(totalTime) + " ms", xLoc, yLoc + (FULL_SIZE / 2) + 15); System.out.println("BILINEAR: " + (endTime - startTime) / 1000000); // BIDUBIC yLoc += FULL_SIZE + PADDING; ((Graphics2D) g).setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC); startTime = System.nanoTime(); drawImage(g, yLoc, false); endTime = System.nanoTime(); totalTime = (endTime - startTime) / 1000000; g.drawString("BICUBIC ", xLoc, yLoc + (FULL_SIZE / 2)); g.drawString(Long.toString(totalTime) + " ms", xLoc, yLoc + (FULL_SIZE / 2) + 15); System.out.println("BICUBIC: " + (endTime - startTime) / 1000000); // getScaledInstance() yLoc += FULL_SIZE + PADDING; ((Graphics2D) g).setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR); startTime = System.nanoTime(); drawImage(g, yLoc, true); endTime = System.nanoTime(); totalTime = (endTime - startTime) / 1000000; g.drawString("getScaled ", xLoc, yLoc + (FULL_SIZE / 2)); g.drawString(Long.toString(totalTime) + " ms", xLoc, yLoc + (FULL_SIZE / 2) + 15); System.out.println("getScaled: " + (endTime - startTime) / 1000000); // Progressive Bilinear yLoc += FULL_SIZE + PADDING; startTime = System.nanoTime(); drawBetterImage(g, yLoc); endTime = System.nanoTime(); totalTime = (endTime - startTime) / 1000000; g.drawString("Progressive ", xLoc, yLoc + (FULL_SIZE / 2)); g.drawString(Long.toString(totalTime) + " ms", xLoc, yLoc + (FULL_SIZE / 2) + 15); System.out.println("faster: " + (endTime - startTime) / 1000000); // Draw image sizes xLoc = 100; int delta = (int) (SCALE_FACTOR * FULL_SIZE); for (int scaledSize = FULL_SIZE; scaledSize > 0; scaledSize -= delta) { g.drawString(scaledSize + " x " + scaledSize, xLoc + Math.max(0, scaledSize / 2 - 20), 15); xLoc += scaledSize + 20; } }
From source file:CalIcon.java
public void paint(Graphics g) { Calendar myCal = Calendar.getInstance(); StringBuffer sb = new StringBuffer(); sb.append(tf.format(myCal.get(Calendar.HOUR))); sb.append(':'); sb.append(tflz.format(myCal.get(Calendar.MINUTE))); sb.append(':'); sb.append(tflz.format(myCal.get(Calendar.SECOND))); String s = sb.toString();//from w w w .j a va 2s .c o m FontMetrics fm = getFontMetrics(getFont()); int x = (getSize().width - fm.stringWidth(s)) / 2; // System.out.println("Size is " + getSize()); g.drawString(s, x, 10); }