當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。