當前位置: 首頁>>代碼示例>>Java>>正文


Java Graphics.setFont方法代碼示例

本文整理匯總了Java中java.awt.Graphics.setFont方法的典型用法代碼示例。如果您正苦於以下問題:Java Graphics.setFont方法的具體用法?Java Graphics.setFont怎麽用?Java Graphics.setFont使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.awt.Graphics的用法示例。


在下文中一共展示了Graphics.setFont方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: paintScore

import java.awt.Graphics; //導入方法依賴的package包/類
/**畫分數等顯示信息*/
public void paintScore(Graphics g) {
	g.setColor(new Color(227, 179, 155));
	//畫當前分數框
	g.fillRoundRect(180, 3, 110, 70, 11, 11);
	//畫最高分框
	g.fillRoundRect(310, 3, 110, 70, 11, 11);
	g.setColor(new Color(239, 198, 0));
	//畫圖標
	g.fillRoundRect(25, 3, 130, 120, 12, 12);
	g.setColor(Color.white);
	g.setFont(new Font("微軟雅黑",Font.PLAIN,20));
	g.drawString("當前分數", 195, 30);
	
	g.drawString(""+score, 200, 57);
	g.drawString("最高分", 335, 30);
	g.drawString(""+mostScore, 335, 57);
	g.setFont(new Font("Impact",Font.PLAIN,48));
	g.drawString("2048", 40, 50);
	g.setFont(new Font("Impact",Font.BOLD,36));
	g.drawString("4 * 4", 50, 90);
}
 
開發者ID:brandonbai,項目名稱:game2048_tetris,代碼行數:23,代碼來源:ClassicPanel.java

示例2: 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

示例3: paintIcon

import java.awt.Graphics; //導入方法依賴的package包/類
public void paintIcon(Component c, Graphics g, int x, int y) {
  g.setColor(Color.black);
  g.drawRect(x, y, swatchWidth-1, swatchHeight-1);

  if (color != null) {
    g.setColor(color);
    g.fillRect(x+1, y+1, swatchWidth-2, swatchHeight-2);
  }
  else {
    // paint no color and a "nil" if the color is null
    g.setColor(UIManager.getColor("controlText"));
    g.setFont(FONT);
    g.drawString("nil",
      x+(swatchWidth - g.getFontMetrics(FONT).stringWidth("nil"))/ 2,
      y+(swatchHeight + g.getFontMetrics(FONT).getAscent())/2);
  }
}
 
開發者ID:ajmath,項目名稱:VASSAL-src,代碼行數:18,代碼來源:ColorButton.java

示例4: 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

示例5: paint

import java.awt.Graphics; //導入方法依賴的package包/類
@Override
public void paint(Graphics g) {
    int length = bannerChars.length;
    for (int i = 0, x = 0; i < length; i++) {
        int wd, ht;
        if (attributes[i] == '^') {
            wd = SMALL_WD;
            ht = SMALL_HT;
            g.setFont(smallFont);
        } else {
            wd = REGULAR_WD;
            ht = REGULAR_HT;
            g.setFont(regularFont);
        }
        int px = (int) (10 * Math.random() + x);
        int py = (int) (10 * Math.random() + ht);
        g.drawChars(bannerChars, i, 1, px, py);
        x += wd;
    }
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:21,代碼來源:NervousText.java

示例6: printNumbersY

import java.awt.Graphics; //導入方法依賴的package包/類
/**
 * Draws numbers on y-axis.
 * 
 * @param g
 *            The {@link Graphics} object.
 */
private void printNumbersY(Graphics g) {
    FontMetrics fm = g.getFontMetrics();
    g.setColor(Color.black);
    Font currentFont = g.getFont();
    g.setFont(new Font(currentFont.toString(), Font.BOLD, currentFont
            .getSize()));

    for (int i = 0; i < hLines; i++) {
        String text = Integer.toString(chart.getyMin() + i
                * chart.getyStep());
        g.drawString(text, xPoint - fm.stringWidth(text) - SPACE,
                rect.height - yPoint - i * hStep + (textHeight / 4));
    }

    g.setFont(currentFont);
}
 
開發者ID:fgulan,項目名稱:java-course,代碼行數:23,代碼來源:BarChartComponent.java

示例7: generate

import java.awt.Graphics; //導入方法依賴的package包/類
public static BufferedImage generate(int width, int height, String message,
		String fontFamily, Color background, Color foreground) {
	BufferedImage bi = new BufferedImage(width, height,
			BufferedImage.TYPE_INT_ARGB);

	Graphics ig2 = null;

	try {
		ig2 = bi.getGraphics();

		ig2.setColor(background);
		ig2.fillRect(0, 0, width, height);

		int fontSize = new Double(height * 0.5d).intValue();
		Font font = new Font(fontFamily, Font.PLAIN, fontSize);
		Map<TextAttribute, Object> map = new Hashtable<TextAttribute, Object>();
		map.put(TextAttribute.WEIGHT, TextAttribute.WEIGHT_BOLD);
		font = font.deriveFont(map);
		ig2.setFont(font);
		ig2.setColor(foreground);
		drawCenteredString(message.toUpperCase(), width, height, ig2);
	} finally {
		if (ig2 != null)
			ig2.dispose();
	}

	return bi;
}
 
開發者ID:jmfgdev,項目名稱:gitplex-mit,代碼行數:29,代碼來源:AvatarGenerator.java

示例8: drawString

import java.awt.Graphics; //導入方法依賴的package包/類
/**
 * 繪製文字
 */
private void drawString(Point st, String str, Color c, Graphics g, int size) {
    g.setFont(new Font("宋體", Font.PLAIN, size));
    g.setColor(c);
    FontMetrics fm = g.getFontMetrics();
    Rectangle2D r2d = fm.getStringBounds(str, g);
    g.drawString(str, st.x, st.y + (int) r2d.getHeight());
}
 
開發者ID:ajtdnyy,項目名稱:ScreenCut,代碼行數:11,代碼來源:ScreenCut.java

示例9: paint

import java.awt.Graphics; //導入方法依賴的package包/類
@Override public void paint(Graphics graphics) {
	super.paint(graphics);
	graphics.drawString("L", 8, inputL.getLocation().y+4);
	graphics.setFont(graphics.getFont().deriveFont(10f));
	graphics.drawString("Loadable", 20, 14);
	ContactUtilities.paintSolderingJoints(graphics, contacts);
}
 
開發者ID:kristian,項目名稱:JDigitalSimulator,代碼行數:8,代碼來源:LoadableRegister.java

示例10: getPreferredSize

import java.awt.Graphics; //導入方法依賴的package包/類
/** Overridden to be able to calculate the preferred size without having
 * to be added to the AWT hierarchy */
public Dimension getPreferredSize() {
    if (isShowing()) {
        return super.getPreferredSize();
    }

    Dimension result = PropUtils.getMinimumPanelSize();
    Graphics g = PropUtils.getScratchGraphics(this);
    g.setFont(getFont());

    String txt = getText();
    Icon i = getIcon();
    FontMetrics fm = g.getFontMetrics(getFont());
    int w = fm.stringWidth(txt);
    int h = fm.getHeight();

    if (i != null) {
        w += (i.getIconWidth() + getIconTextGap());
        h = Math.max(h, result.height);
    }

    Insets ins = getInsets();

    if (ins != null) {
        w += (ins.left + ins.right);
        h += (ins.top + ins.bottom);
    }

    w += 22; //A small fudge factor to avoid truncated text

    result.width = Math.max(result.width, w);
    result.height = Math.max(result.height, h);

    return result;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:37,代碼來源:CheckboxInplaceEditor.java

示例11: 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

示例12: getTextPixels

import java.awt.Graphics; //導入方法依賴的package包/類
public static int[] getTextPixels(String text, JmolFont font3d, Object gObj,
                                  Object image, int width, int height,
                                  int ascent) {
  Graphics g = (Graphics) gObj;
  g.setColor(Color.black);
  g.fillRect(0, 0, width, height);
  g.setColor(Color.white);
  g.setFont((Font) font3d.font);
  g.drawString(text, 0, ascent);
  return grabPixels(image, width, height, null, 0, 0);
}
 
開發者ID:etomica,項目名稱:etomica,代碼行數:12,代碼來源:Image.java

示例13: getTextArea

import java.awt.Graphics; //導入方法依賴的package包/類
private Dimension getTextArea(Graphics g, String text)
{
	Dimension d = new Dimension();
	if( g != null )
	{
		g.setFont(DEFAULT_FONT);
		Rectangle2D textSize = g.getFontMetrics().getStringBounds(text, g);
		d.width = (int) textSize.getWidth();
		d.height = (int) textSize.getHeight();
	}
	return d;
}
 
開發者ID:equella,項目名稱:Equella,代碼行數:13,代碼來源:TaskRenderer.java

示例14: runTest

import java.awt.Graphics; //導入方法依賴的package包/類
public void runTest(Object ctx, int numReps) {
    TextContext tctx = (TextContext)ctx;
    Graphics g = tctx.graphics;
    g.setFont(tctx.font);
    String text = tctx.text;
    do {
        g.drawString(text, 40, 40);
    } while (--numReps >= 0);
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:10,代碼來源:TextRenderTests.java

示例15: paint

import java.awt.Graphics; //導入方法依賴的package包/類
@Override public void paint(Graphics graphics) {
	super.paint(graphics);
	graphics.drawString("+", 8, inputI.getLocation().y+4);
	graphics.drawString("C", 8, inputC.getLocation().y+4);
	graphics.drawString("R", 8, inputR.getLocation().y+4);
	graphics.setFont(graphics.getFont().deriveFont(10f));
	graphics.drawString("Shift", 20, 22);
	ContactUtilities.paintSolderingJoints(graphics, contacts);
}
 
開發者ID:kristian,項目名稱:JDigitalSimulator,代碼行數:10,代碼來源:LoadableShiftRegister.java


注:本文中的java.awt.Graphics.setFont方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。