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


Java Graphics.drawString方法代码示例

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


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

示例1: paintComponent

import java.awt.Graphics; //导入方法依赖的package包/类
public void paintComponent(Graphics g) {
    g.setColor(Color.WHITE);
    g.fillRect(0, 0, fpd.width, fpd.height);

    g.setColor(Color.RED);
    FontRenderContext frc = ((Graphics2D)g).getFontRenderContext();
    LineMetrics lm = f.getLineMetrics(fps, frc);
    int h = (int)(fpd.height - 20 - lm.getAscent());
    g.drawLine(20, h, fpd.width - 20, h);
    h = fpd.height - 20;
    g.drawLine(20, h, fpd.width - 20, h);
    h = (int)(fpd.height - 20 + lm.getDescent());
    g.drawLine(20, h, fpd.width - 20, h);

    g.setColor(Color.BLACK);
    g.setFont(f);
    g.drawString(fps, 50, fpd.height - 20);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:19,代码来源:UnderlineTest.java

示例2: paint

import java.awt.Graphics; //导入方法依赖的package包/类
@Override public void paint(Graphics graphics) {
	graphics.setColor(Color.BLACK);
	graphics.drawPolyline(new int[]{9 , 9 , 5 , 5, size.width-5, size.width-5, size.width-9, size.width-9},
			new int[]{30, 25, 25, 0, 0           , 25          , 25          , 30          }, 8);
	graphics.setFont(graphics.getFont().deriveFont(10f));
	graphics.drawString("Binary", 25, 22);
	graphics.setFont(graphics.getFont().deriveFont(8f));
	graphics.drawString("C", 8, inputC.getLocation().y+4);
	graphics.drawString("R", 8, inputR.getLocation().y+4);
	for(int output=0;output<outputs.getContactsCount();output++) {
		int top = 30+output*20;
		graphics.drawRect(5, top, size.width-10, 20);
		graphics.drawString("+", size.width-12, top+13);
	}
	ContactUtilities.paintSolderingJoints(graphics, contacts);
}
 
开发者ID:kristian,项目名称:JDigitalSimulator,代码行数:17,代码来源:BinaryCounter.java

示例3: paintComponent

import java.awt.Graphics; //导入方法依赖的package包/类
@Override
protected void paintComponent(Graphics g) {
    if (font.canDisplayUpTo(text) == -1) {
        g.setColor(Color.black);
        g.setFont(font);
        g.drawString(text, 70, 110);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:9,代码来源:MissingGlyphTest.java

示例4: paintComponent

import java.awt.Graphics; //导入方法依赖的package包/类
@Override
public void paintComponent(Graphics g)
{
	super.paintComponent(g);
	
	if(window.paintReady)
	{
		PaintFlightLog(g);
		
		if(paint_arg == PAINT_ARG_FLIGHT_TELEMETRY)
			PaintFlightTelemetry(g);
	}
	else
	{
		if(paint_arg == PAINT_ARG_CONNECTION_RED) g.setColor(Color.RED);
		g.drawString("Remember to start the server!", 110, 50);
		if(paint_arg == PAINT_ARG_CONNECTION_RED) g.setColor(Color.BLACK);
		
		g.drawString("Enter target apoapsis height:", 105, 165);
	}
	
}
 
开发者ID:janw23,项目名称:New-Kepard,代码行数:23,代码来源:JWindow.java

示例5: drawCenteredText

import java.awt.Graphics; //导入方法依赖的package包/类
private void drawCenteredText(Graphics g, String message, boolean alignCenter) {
	String[] lines = message.split("\n");
	
	FontMetrics fm = g.getFontMetrics();
	int height = lines.length * fm.getHeight();
	int width = 0;
	if (!alignCenter) {
		for (String line : lines) {
			if (fm.stringWidth(line) > width) {
				width = fm.stringWidth(line);
			}
		}
	}
	
	for (int i = 0; i < lines.length; i++) {
		g.drawString(
			lines[i],
			(getWidth() - (alignCenter ? fm.stringWidth(lines[i]) : width)) / 2,
			(getHeight() - height) / 2 + i*fm.getHeight()
		);
	}
}
 
开发者ID:mgropp,项目名称:pdfjumbler,代码行数:23,代码来源:PdfList.java

示例6: paint

import java.awt.Graphics; //导入方法依赖的package包/类
@Override
public void paint(Graphics g) {
    if (md != null) {
        md.mat.unit();
        md.mat.translate(-(md.xmin + md.xmax) / 2,
                -(md.ymin + md.ymax) / 2,
                -(md.zmin + md.zmax) / 2);
        md.mat.mult(amat);
        md.mat.scale(xfac, -xfac, 16 * xfac / getSize().width);
        md.mat.translate(getSize().width / 2, getSize().height / 2, 8);
        md.transformed = false;
        md.paint(g);
        setPainted();
    } else if (message != null) {
        g.drawString("Error in model:", 3, 20);
        g.drawString(message, 10, 40);
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:19,代码来源:ThreeD.java

示例7: paint

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

    super.paint(g);
    Rectangle bounds = getBounds();
    if (superIsButton) {
        return;
    }
    Dimension size = getSize();
    Color oldColor = g.getColor();

    // draw border
    g.setColor(getBackground());
    g.fill3DRect(0, 0, size.width, size.height, false);
    g.fill3DRect(3, 3, size.width - 6, size.height - 6, true);

    // draw text
    FontMetrics metrics = g.getFontMetrics();
    int centerX = size.width / 2;
    int centerY = size.height / 2;
    int textX = centerX - (metrics.stringWidth(labelString) / 2);
    int textY = centerY
            + ((metrics.getMaxAscent() + metrics.getMaxDescent()) / 2);
    g.setColor(getForeground());
    g.drawString(labelString, textX, textY);

    g.setColor(oldColor);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:29,代码来源:LightweightEventTest.java

示例8: draw

import java.awt.Graphics; //导入方法依赖的package包/类
public void draw(DrawingPanel panel, Graphics g) {
if(x==null) {
     return;
   }
   road.setBlock(0, 0, new byte[roadLength][1]);
   for(int i = 0;i<numberOfCars;i++) {
     if(x[i] != -1) {
   	road.setValue(x[i], 0, (byte) 1);
     }
   }
   road.draw(panel, g);
   g.drawString("Number of Steps = "+steps, 10, 20);
   g.drawString("Flow = "+ControlUtils.f3(flow/(roadLength*steps)), 10, 40);
   g.drawString("Density = "+ControlUtils.f3(((double) numberOfCars)/(roadLength)), 10, 60);
 }
 
开发者ID:robotenique,项目名称:intermediateProgramming,代码行数:16,代码来源:Freeway.java

示例9: paint

import java.awt.Graphics; //导入方法依赖的package包/类
@Override
public void paint(Graphics g) {
	((Graphics2D)g).setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
	super.paint(g);

	if (page == null) {
		return;
	}

	Image cachedImage;
	
	if (imageCache.containsKey(page)) {
		cachedImage = imageCache.get(page);
	} else {
		try {
			cachedImage = renderer.renderPage(page, thumbnailWidth, thumbnailHeight);
		}
		catch (IOException e) {
			throw new RuntimeException(e);
		}
		imageCache.put(page, cachedImage);
	}
	
	g.drawImage(cachedImage, padding, padding, null);
	g.setColor(Color.LIGHT_GRAY);
	g.drawRect(padding, padding, cachedImage.getWidth(null), cachedImage.getHeight(null));
	
	g.setColor(this.getForeground());
	g.drawString(
		page.toString(),
		thumbnailWidth + 2*padding,
		padding + g.getFontMetrics().getAscent()
	);
}
 
开发者ID:mgropp,项目名称:pdfjumbler,代码行数:35,代码来源:PdfCellRenderer.java

示例10: paintText

import java.awt.Graphics; //导入方法依赖的package包/类
public void paintText(Graphics g, Point position) {
    if (name != null && g != null && position != null) {
        if (getFont() == null) {
            Font f = getDefaultFont();
            setFont(new Font(f.getName(), Font.BOLD, f.getSize()));
        }
        g.setColor(Color.DARK_GRAY);
        g.setFont(getFont());
        g.drawString(name, position.x+MapMarkerDot.DOT_RADIUS+2, position.y+MapMarkerDot.DOT_RADIUS);
    }
}
 
开发者ID:berniejenny,项目名称:MapAnalyst,代码行数:12,代码来源:MapObjectImpl.java

示例11: renderTag

import java.awt.Graphics; //导入方法依赖的package包/类
public void renderTag(Graphics g) {
	if (pos.y == 110) {
		g.setColor(Color.WHITE);
		g.setFont(new Font("Times New Java", Font.BOLD, 20));
		g.drawString("" + (int)((pos.x + 40)/50), (int)(pos.x + 10), (int)(pos.y + 10));
	}
}
 
开发者ID:ritcat14,项目名称:The-Mysterious-Mind-Of-Jack,代码行数:8,代码来源:InventButton.java

示例12: paintComponent

import java.awt.Graphics; //导入方法依赖的package包/类
@Override
public void paintComponent(Graphics g)
{
   super.paintComponent(g); 
   this.setBackground(Color.WHITE);

   // set new drawing color using integers
   g.setColor(new Color(255, 0, 0));
   g.fillRect(15, 25, 100, 20);
   g.drawString("Current RGB: " + g.getColor(), 130, 40);

   // set new drawing color using floats
   g.setColor(new Color(0.50f, 0.75f, 0.0f));
   g.fillRect(15, 50, 100, 20);
   g.drawString("Current RGB: " + g.getColor(), 130, 65);

   // set new drawing color using static Color objects
   g.setColor(Color.BLUE);
   g.fillRect(15, 75, 100, 20);
   g.drawString("Current RGB: " + g.getColor(), 130, 90);

   // display individual RGB values
   Color color = Color.MAGENTA;
   g.setColor(color);
   g.fillRect(15, 100, 100, 20);
   g.drawString("RGB values: " + color.getRed() + ", " +
      color.getGreen() + ", " + color.getBlue(), 130, 115);
}
 
开发者ID:cleitonferreira,项目名称:LivroJavaComoProgramar10Edicao,代码行数:29,代码来源:ColorJPanel.java

示例13: createPushButton

import java.awt.Graphics; //导入方法依赖的package包/类
/**
* Create the "Push" button.
* 
* @return the "Push" button.
*/
private ToolbarButton createPushButton() {
  return new ToolbarButton(createPushAction(), false) {
	@Override
	protected void paintComponent(Graphics g) {
		super.paintComponent(g);

		String str = "";
		if (pushesAhead > 0) {
			str = "" + pushesAhead;
		}
		if (pushesAhead > 9) {
			pushButton.setHorizontalAlignment(SwingConstants.LEFT);
		} else {
			pushButton.setHorizontalAlignment(SwingConstants.CENTER);
		}
		g.setFont(g.getFont().deriveFont(Font.BOLD, 8.5f));
		FontMetrics fontMetrics = g.getFontMetrics(g.getFont());
		int stringWidth = fontMetrics.stringWidth(str);
		int stringHeight = fontMetrics.getHeight();
		g.setColor(new Color(255, 255, 255, 100));
		g.fillRect(pushButton.getWidth() - stringWidth - 1, pushButton.getHeight() - stringHeight, stringWidth,
				stringHeight);
		g.setColor(Color.BLACK);
		g.drawString(str, pushButton.getWidth() - stringWidth, pushButton.getHeight() - fontMetrics.getDescent());
	}
};
}
 
开发者ID:oxygenxml,项目名称:oxygen-git-plugin,代码行数:33,代码来源:ToolbarPanel.java

示例14: paintText

import java.awt.Graphics; //导入方法依赖的package包/类
/**
 * Renders the text.
 */
private void paintText(Graphics g, int w, int h) {
    g.setFont(getFont());
    String text = getHeapSizeText();
    FontMetrics fm = g.getFontMetrics();
    int textWidth = fm.stringWidth(text);
    g.drawString(text, (w - maxTextWidth) / 2 + (maxTextWidth - textWidth), 
            h / 2 + fm.getAscent() / 2 - 2);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:12,代码来源:HeapView.java

示例15: paintText

import java.awt.Graphics; //导入方法依赖的package包/类
private void paintText(Graphics g, int w, int h) {
    g.setFont(getFont());
    String text = getString();
    FontMetrics fm = g.getFontMetrics();
    int textWidth = fm.stringWidth(text);
    g.drawString(text, (w - textWidth) / 2,
            h - fm.getDescent() - ((h - fm.getHeight()) / 2));
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:9,代码来源:ResultBar.java


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