当前位置: 首页>>代码示例>>Java>>正文


Java Graphics2D.drawString方法代码示例

本文整理汇总了Java中java.awt.Graphics2D.drawString方法的典型用法代码示例。如果您正苦于以下问题:Java Graphics2D.drawString方法的具体用法?Java Graphics2D.drawString怎么用?Java Graphics2D.drawString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.awt.Graphics2D的用法示例。


在下文中一共展示了Graphics2D.drawString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: paintComponent

import java.awt.Graphics2D; //导入方法依赖的package包/类
public void paintComponent(Graphics g) {
     super.paintComponent(g);
     Graphics2D g2 = (Graphics2D)g;
     FontRenderContext frc = new FontRenderContext(null, true, true);
     Font f = helvFont.deriveFont(Font.PLAIN, 40);
     System.out.println("font = " +f.getFontName());
     GlyphVector gv = f.createGlyphVector(frc, codes);
     g.setFont(f);
     g.setColor(Color.white);
     g.fillRect(0,0,400,400);
     g.setColor(Color.black);
     g2.drawGlyphVector(gv, 5,200);
     g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
                         RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
     g2.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS,
                         RenderingHints.VALUE_FRACTIONALMETRICS_ON);
     g2.drawString(str, 5, 250);
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:19,代码来源:HelvLtOblTest.java

示例2: paint

import java.awt.Graphics2D; //导入方法依赖的package包/类
@Override
public void paint(Graphics g1) {
	if (redraw) {
		redraw = false;
		Graphics2D g = (Graphics2D) legenda.getGraphics();
		g.setColor(Color.WHITE);
		g.fillRect(0, 0, 110, (SQUARE_L + LINE_H) * (clusters + 1));
		for (int i = 1; i <= clusters + 1; i++) {
			g.setColor(JavaWatColor.getColor((i - 1)));
			g.fillRect(START_SQUARE_W, (START_SQUARE_H + (SQUARE_L + LINE_H) * (i - 1)), SQUARE_L, SQUARE_L);
			g.setColor(Color.BLACK);
			g.drawString("Cluster " + i, START_SQUARE_W + SQUARE_L + SQUARE_L, (START_SQUARE_H + (SQUARE_L + LINE_H) * (i - 1) + LINE_H));
		}
	}
	g1.drawImage(legenda, 0, 0, null);
}
 
开发者ID:max6cn,项目名称:jmt,代码行数:17,代码来源:DispersionkMeanPanel.java

示例3: paint

import java.awt.Graphics2D; //导入方法依赖的package包/类
@Override
public void paint(Graphics g1)
{
	Graphics2D g = (Graphics2D)g1;

	Dimension size = getSize();
	g.setColor(getBackground());
	g.fillRect(0, 0, size.width, size.height);
	g.setColor(new Color(40,40,40));

	//FontMetrics tm = g.getFontMetrics(topFont);
	FontMetrics bm = g.getFontMetrics(bottomFont);

	if (topLine != null)
	{
		g.setFont(topFont);
		g.drawString(topLine, 5, size.height/2 - 2);
	}
	if (bottomLine != null)
	{
		g.setFont(bottomFont);
		g.drawString(bottomLine, 5, size.height/2 + bm.getHeight() - 2);
	}
}
 
开发者ID:drytoastman,项目名称:scorekeeperfrontend,代码行数:25,代码来源:DriverTable.java

示例4: paintComponent

import java.awt.Graphics2D; //导入方法依赖的package包/类
@Override protected void paintComponent(Graphics arg0)
{
	Graphics2D g = (Graphics2D) arg0;
	g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
	int w = chartWidth;
	int h = getHeight();
	g.setColor(Color.black);
	g.fillRect(0, 0, getWidth(), getHeight());

	g.drawImage(bufferedImages[drawIndex], chartXOffset, 0, w, h, null);
	
	if (displayMarker){
		g.setColor(Color.gray);
		g.drawLine(displayMarkerX, 0, displayMarkerX, h);
		g.drawString(String.format("%.1fMHz", displayMarkerFrequency/1000000.0), displayMarkerX+5, h/2);
	}//finish marker 
	
	g.setColor(Color.white);
	int x	= chartXOffset + w - 250;
	int y	= h - 20;
	g.drawString(renderingInfo, x, y-20);
	g.drawString(statusMessage, x, y);
}
 
开发者ID:pavsa,项目名称:hackrf-spectrum-analyzer,代码行数:24,代码来源:WaterfallPlot.java

示例5: getResolutionVariant

import java.awt.Graphics2D; //导入方法依赖的package包/类
@Override
public Image getResolutionVariant(double destImageWidth, double destImageHeight) {

    int w = (int) destImageWidth;
    int h = (int) destImageHeight;

    BufferedImage img = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
    Graphics2D g = img.createGraphics();
    g.scale(scaleX, scaleY);
    int red = (int) (255 / scaleX);
    int green = (int) (250 / scaleX);
    int blue = (int) (20 / scaleX);
    g.setColor(new Color(red, green, blue));
    g.fillRect(0, 0, width, height);

    g.setColor(Color.decode("#87CEFA"));
    Font f = g.getFont();
    g.setFont(new Font(f.getName(), Font.BOLD, 24));
    g.drawString(String.format("scales: [%1.2fx, %1.2fx]", scaleX, scaleY),
            width / 6, height / 2);

    g.dispose();
    return img;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:25,代码来源:WindowResizingOnSetLocationTest.java

示例6: draw

import java.awt.Graphics2D; //导入方法依赖的package包/类
public void draw(Graphics2D g) {
      float radius = Beacon.BEACON_RADIUS;
      float diameter = Beacon.BEACON_RADIUS * 2;
      
      Ellipse2D.Double shape = new Ellipse2D.Double(drawLocation.getX() - radius,
      		drawLocation.getY() - radius, diameter, diameter);

      g.setColor(BEACON_COLOR);
      g.fill(shape);

      g.setStroke(JSpaceSettlersComponent.THICK_STROKE);
      g.setColor(BEACON_LINE_COLOR);
      g.draw(shape);

      // add an E to make it clear it is an energy beacon
g.setPaint(Color.BLACK);
g.drawString("E", (int) drawLocation.getX()-3, (int) drawLocation.getY() + 4);

  }
 
开发者ID:amymcgovern,项目名称:spacesettlers,代码行数:20,代码来源:BeaconGraphics.java

示例7: main

import java.awt.Graphics2D; //导入方法依赖的package包/类
public static void main(String[] args) {
    Locale.setDefault(Locale.US);

    final BufferedImage image
        = new BufferedImage(512, 512, BufferedImage.TYPE_INT_ARGB);

    final Graphics2D g2d = image.createGraphics();
    try {
        g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                             RenderingHints.VALUE_ANTIALIAS_ON);
        g2d.setRenderingHint(RenderingHints.KEY_RENDERING,
                             RenderingHints.VALUE_RENDER_QUALITY);
        g2d.scale(2.0, 2.0);

        g2d.setColor(Color.red);
        g2d.draw(new Rectangle2D.Float(10, 10, 100, 100));
        g2d.setColor(Color.blue);
        g2d.fill(new Rectangle2D.Float(12, 12, 98, 98));
        g2d.setColor(Color.green);
        g2d.setFont(new Font(Font.SERIF, Font.BOLD, 14));

        for (int i = 0; i < 15; i++) {
            g2d.drawString("Testing Compression ...", 20, 20 + i * 16);
        }

        final String[] fileSuffixes = ImageIO.getWriterFileSuffixes();

        final Set<String> testedWriterClasses = new HashSet<String>();

        for (String suffix : fileSuffixes) {

            if (!IGNORE_FILE_SUFFIXES.contains(suffix)) {
                final Iterator<ImageWriter> itWriters
                    = ImageIO.getImageWritersBySuffix(suffix);

                final ImageWriter writer;
                final ImageWriteParam writerParams;

                if (itWriters.hasNext()) {
                    writer = itWriters.next();

                    if (testedWriterClasses.add(writer.getClass().getName())) {
                        writerParams = writer.getDefaultWriteParam();

                        if (writerParams.canWriteCompressed()) {
                            testCompression(image, writer, writerParams, suffix);
                        }
                    }
                } else {
                    throw new RuntimeException("Unable to get writer !");
                }
            }
        }
    } catch (IOException ioe) {
        throw new RuntimeException("IO failure", ioe);
    }
    finally {
        g2d.dispose();
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:61,代码来源:ImageWriterCompressionTest.java

示例8: draw

import java.awt.Graphics2D; //导入方法依赖的package包/类
public void draw(Graphics2D g) {
	g.setColor(Color.BLACK); 
	g.fillRect(0, 0, GamePanel.WIDTH, GamePanel.HEIGHT);
	g.setColor(Color.WHITE); 
	g.setFont(font);
	g.drawString("Game Paused", 110, 110);
}
 
开发者ID:tonikolaba,项目名称:BatBat-Game,代码行数:8,代码来源:PauseState.java

示例9: drawToolTip

import java.awt.Graphics2D; //导入方法依赖的package包/类
private void drawToolTip(Graphics2D g) {
	if (currentToolTip != null) {
		g.setFont(LABEL_FONT);
		Rectangle2D stringBounds = LABEL_FONT.getStringBounds(currentToolTip, g.getFontRenderContext());
		g.setColor(TOOLTIP_COLOR);
		Rectangle2D bg = new Rectangle2D.Double((toolTipX) - stringBounds.getWidth() - 15,
				(toolTipY - (stringBounds.getHeight() / 2)), stringBounds.getWidth() + 6, Math.abs(stringBounds
						.getHeight()) + 4);
		g.fill(bg);
		g.setColor(Color.black);
		g.draw(bg);
		g.drawString(currentToolTip, (float) ((toolTipX) - stringBounds.getWidth() - 12),
				(float) ((toolTipY + stringBounds.getHeight() * 0.5) + 1));
	}
}
 
开发者ID:transwarpio,项目名称:rapidminer,代码行数:16,代码来源:DensityPlotter.java

示例10: main

import java.awt.Graphics2D; //导入方法依赖的package包/类
public static void main(final String[] args) throws IOException {
    for (int  point = 5; point < 11; ++point) {
        Graphics2D g2d = bi.createGraphics();
        g2d.setFont(new Font(Font.DIALOG, Font.PLAIN, point));
        g2d.scale(scale, scale);
        g2d.setColor(Color.WHITE);
        g2d.fillRect(0, 0, width, height);
        g2d.setColor(Color.green);
        g2d.drawString(TEXT, 0, 20);
        int length = g2d.getFontMetrics().stringWidth(TEXT);
        if (length < 0) {
            throw new RuntimeException("Negative length");
        }
        for (int i = (length + 1) * scale; i < width; ++i) {
            for (int j = 0; j < height; ++j) {
                if (bi.getRGB(i, j) != Color.white.getRGB()) {
                    g2d.drawLine(length, 0, length, height);
                    ImageIO.write(bi, "png", new File("image.png"));
                    System.out.println("length = " + length);
                    System.err.println("Wrong color at x=" + i + ",y=" + j);
                    System.err.println("Color is:" + new Color(bi.getRGB(i,
                                                                         j)));
                    throw new RuntimeException("Test failed.");
                }
            }
        }
        g2d.dispose();
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:30,代码来源:IncorrectTextSize.java

示例11: paintIcon

import java.awt.Graphics2D; //导入方法依赖的package包/类
@Override
public void paintIcon(Component c, Graphics g, int x, int y) {
    Graphics2D g2d = (Graphics2D) g.create();        
    g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    g2d.setFont(font.deriveFont((float)size));
    g2d.setColor(color);
    g2d.drawString(text, x, y + getIconHeight());
    g2d.dispose();
}
 
开发者ID:VISNode,项目名称:VISNode,代码行数:10,代码来源:VectorIcon.java

示例12: drawLowerLeftString

import java.awt.Graphics2D; //导入方法依赖的package包/类
/**
 * Place a string in the lower left of a bounding rectangle (eg a plot)
 * @param g
 * @param text
 * @param rect
 * @param font
 * @param xScale
 * @param yScale
 */
public static void drawLowerLeftString(Graphics g, String text, Rectangle2D rect, Font font, double xScale, double yScale, boolean whiteBox) {
	// Get the original font
	Font oldFont = g.getFont();
    // Get the FontMetrics
    FontMetrics metrics = g.getFontMetrics(font);
    // Determine the X coordinate for the text
    int x = 10;
    // Determine the Y coordinate for the text (note we add the ascent, as in java 2d 0 is top of the screen)
    int y = (int) ((rect.getHeight() * yScale - metrics.getHeight()) ) + metrics.getAscent() - 5;
    // Set the font
    Graphics2D g2 = (Graphics2D) g;
    g2.setFont(font);
    
    if (whiteBox) {
    	//draw a white box behind the text
	    int textWidth = (int) font.getStringBounds(text, g2.getFontRenderContext()).getWidth() + 2;
	    int textHeight = metrics.getHeight() + 2;
	    Color oldColor = g2.getColor();
	    g2.setColor(Color.white);
	    g2.fillRect(x-1, y-textHeight+4, textWidth, textHeight);
	    g2.setColor(oldColor);
    }
    // Draw the String
    g2.drawString(text, x , y);
    // Reset font
    g2.setFont(oldFont);
}
 
开发者ID:iedadata,项目名称:geomapapp,代码行数:37,代码来源:GeneralUtils.java

示例13: getScreenImages

import java.awt.Graphics2D; //导入方法依赖的package包/类
static BufferedImage getScreenImages() {

        final BufferedImage img = new BufferedImage(maxBounds.width, maxBounds.height, BufferedImage.TYPE_INT_RGB);
        Graphics2D g = img.createGraphics();
        g.setColor(Color.WHITE);
        g.fillRect(0, 0, maxBounds.width, maxBounds.height);
        g.translate(-maxBounds.x, -maxBounds.y);

        g.setStroke(new BasicStroke(8f));
        for (int i = 0; i < screenBounds.length; i++) {
            Rectangle r = screenBounds[i];
            g.setColor(Color.BLACK);
            g.drawRect(r.x, r.y, r.width, r.height);

            g.setColor(Color.ORANGE);
            Rectangle cr = getCenterRect(r);
            g.fillRect(cr.x, cr.y, cr.width, cr.height);

            double scaleX = scales[i][0];
            double scaleY = scales[i][1];
            float fontSize = maxBounds.height / 7;
            g.setFont(g.getFont().deriveFont(fontSize));
            g.setColor(Color.BLUE);
            g.drawString(String.format("Scale: [%2.1f, %2.1f]", scaleX, scaleY),
                    r.x + r.width / 8, r.y + r.height / 2);

        }

        g.dispose();

        return img;
    }
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:33,代码来源:RobotMultiDPIScreenTest.java

示例14: drawToolTip

import java.awt.Graphics2D; //导入方法依赖的package包/类
private void drawToolTip(Graphics2D g) {
	if (currentToolTip != null) {
		g.setFont(LABEL_FONT);
		Rectangle2D stringBounds = LABEL_FONT.getStringBounds(currentToolTip, g.getFontRenderContext());
		g.setColor(TOOLTIP_COLOR);
		Rectangle2D bg = new Rectangle2D.Double(toolTipX - stringBounds.getWidth() / 2 - 4, toolTipY
				- stringBounds.getHeight() / 2 - 2, stringBounds.getWidth() + 5, Math.abs(stringBounds.getHeight()) + 3);
		g.fill(bg);
		g.setColor(Color.black);
		g.draw(bg);
		g.drawString(currentToolTip, (float) (toolTipX - stringBounds.getWidth() / 2) - 2, (float) (toolTipY + 3));
	}
}
 
开发者ID:transwarpio,项目名称:rapidminer,代码行数:14,代码来源:BoundDiagram.java

示例15: bordaLeftRigth

import java.awt.Graphics2D; //导入方法依赖的package包/类
public void bordaLeftRigth(Graphics2D g, boolean isrigth) {
        FontMetrics fm = g.getFontMetrics();
        String vl = FormateUnidadeMedida(H);
        int pre_x = (isrigth ? getLeftWidth() : getLeft());
        int traco = largTraco < margem ? largTraco : margem;
        traco = (isrigth ? -traco : traco);
        int xIni = pre_x + (isrigth ? -2 : 2);
        int xFim = xIni + 2 * traco;
        int yIni = getTop() + margem;
        int yFim = getTopHeight() - margem;
        int xLin = xIni;
//        int pre_x = (isrigth ? getLeftWidth() - margem : getLeft());
//        int traco = largTraco < margem ? largTraco : margem;
//        int xIni = pre_x + (margem - traco) / 2;
//        int xFim = xIni + traco;
//        int yIni = getTop() + margem;
//        int yFim = getTopHeight() - margem;
//        int xLin = pre_x + margem / 2;

        g.setColor(getCorRegua());
        g.drawLine(xIni, yIni, xFim, yIni);
        g.drawLine(xIni, yFim, xFim, yFim);
        g.drawLine(xLin, yIni, xLin, yFim);

        int blc = calculeSubEspaco(W);
        int sr = yIni;
        xFim -= traco;

        int dv = modInteiro(blc);
        int subblc = 0;
        if (dv > 0) {
            subblc = blc / dv;
        }
        while (sr < yFim) {
            if (dv > 0) {
                int a = blc - subblc;
                while (a > 0) {
                    if (sr + a < yFim) {
                        g.drawLine(xIni, sr + a, xFim - traco / 2, sr + a);
                    }
                    a -= subblc;
                }
            }
            g.drawLine(xIni, sr, xFim, sr);
            sr += blc;
        }

        if (isMostrarTextoRegua()) {
            int degrees = isrigth ? 90 : -90;
            int desse = isrigth ? 0 : fm.stringWidth(vl);
            int centra = fm.getHeight() / 2 - fm.getDescent();
            centra = isrigth ? -centra : centra;

            AffineTransform at = AffineTransform.getRotateInstance(Math.toRadians(degrees));
            Font f = new Font(getFont().getName(), Font.BOLD, getFont().getSize());
            g.setFont(f.deriveFont(at));
            g.setColor(getForeColor());
            xLin = pre_x - (isrigth ? margem / 2 : -margem / 2);
            yIni = yIni + (H - fm.stringWidth(vl)) / 2 + desse;
            g.drawString(vl, xLin + centra, yIni);
            g.setFont(getFont());
        }
    }
 
开发者ID:chcandido,项目名称:brModelo,代码行数:64,代码来源:baseDrawer.java


注:本文中的java.awt.Graphics2D.drawString方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。