本文整理汇总了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);
}
示例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);
}
示例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);
}
}
示例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);
}
示例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;
}
}
示例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);
}
示例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;
}
示例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());
}
示例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);
}
示例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;
}
示例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());
}
};
}
示例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);
}
示例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;
}
示例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);
}
示例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);
}