当前位置: 首页>>代码示例>>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;未经允许,请勿转载。