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


Java Font.getSize方法代码示例

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


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

示例1: init

import java.awt.Font; //导入方法依赖的package包/类
@Override
	public void init(GameContainer container) throws SlickException {
		this.container = container;
		this.map = new TiledMap("/home/enzo/newmap.tmx");

		SpriteSheet spriteSheet = new SpriteSheet("/home/enzo/SpriteSheetAnim.png", 64, 64);
		this.animations[0] = loadAnimation(spriteSheet, 0, 1, 0);
		this.animations[1] = loadAnimation(spriteSheet, 0, 1, 1);
		this.animations[2] = loadAnimation(spriteSheet, 0, 1, 2);
		this.animations[3] = loadAnimation(spriteSheet, 0, 1, 3);
		this.animations[4] = loadAnimation(spriteSheet, 1, 9, 0);
		this.animations[5] = loadAnimation(spriteSheet, 1, 9, 1);
		this.animations[6] = loadAnimation(spriteSheet, 1, 9, 2);
		this.animations[7] = loadAnimation(spriteSheet, 1, 9, 3);
	
		Font font = new Font("Verdana", Font.BOLD, 20);
		UnicodeFont uFont = new UnicodeFont(font, font.getSize(), font.isBold(), font.isItalic());
		nameInput = new TextField(container, uFont, 150,20,500,35, new ComponentListener()
	        {
	         public void componentActivated(AbstractComponent source) {
	            message = "Entered1: "+nameInput.getText();
	            nameInput.setFocus(true);
	         }

	    });
		
//		ComponentListener listener = new ComponentListener();
//		TextField nameInput = new TextField(arg0, truetypefont, 150,20,500,35, listener);
//		
//		{
//	        public void componentActivated(AbstractComponent source) {
//	           System.out.println("Entered1: "+nameInput.getText());
//	        }
//	   });
	
	}
 
开发者ID:EnzoMolion,项目名称:Projet-PLA,代码行数:37,代码来源:WindowGame.java

示例2: formComponentResized

import java.awt.Font; //导入方法依赖的package包/类
private void formComponentResized(java.awt.event.ComponentEvent evt) {
        if(System.currentTimeMillis()-lastResizeTime<500) return; // don't resize too often or we can generate a storm of component resizing
        // handle label font sizing here
        double labelWidth=getWidth(); // width of text (approx)
        double parentWidth=getParent().getWidth(); // width of panel holding label
        
        if(labelWidth<200) labelWidth=200;
        double r=labelWidth/parentWidth;  // r is ratio text/container, 2 means text 2 times too large
        if(r>.8 && r<.95) return;
        final double mn=.3, mx=2.3;
        if(r<mn) r=mn; if(r>mx) r=mx;
        final double ratio=0.9; // label should be this fraction of width, we undersize to prevent cycling
        
        Font f=getFont();
        int size=f.getSize(); // old font size
        int newsize=(int)Math.floor(size/r*ratio); // new size is old size divided by width ratio
        if(newsize<MIN_FONT_SIZE) newsize=MIN_FONT_SIZE; if(newsize>MAX_FONT_SIZE) newsize=MAX_FONT_SIZE;
        if(size==newsize) return;
//        System.out.println("labelWidth="+labelWidth+" parentWidth="+parentWidth+" newsize="+newsize+" string="+getText());
        currentFont=f.deriveFont((float)newsize);
        setFont(currentFont);
        lastResizeTime=System.currentTimeMillis();
        
    }
 
开发者ID:SensorsINI,项目名称:jaer,代码行数:25,代码来源:DynamicFontSizeJLabel.java

示例3: UI

import java.awt.Font; //导入方法依赖的package包/类
private static void UI() {
    Frame frame = new Frame("Test frame");
    Choice choice = new Choice();

    Stream.of(new String[]{"item 1", "item 2", "item 3"}).forEach(choice::add);
    frame.add(choice);
    frame.setBounds(100, 100, 400, 200);

    frame.setVisible(true);
    Font font = choice.getFont();
    int size = font.getSize();
    int height = choice.getBounds().height;
    try {
        if (height < size) {
            throw new RuntimeException("Test failed");
        }
    } finally {
        frame.dispose();
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:21,代码来源:ChoiceTest.java

示例4: drawString

import java.awt.Font; //导入方法依赖的package包/类
/**
     * 随机画字符
     *
     * @param image 图片
     * @return 返回画的字符串
     */
    private String drawString(BufferedImage image) {
        Random r = new Random();
        Graphics2D g2 = (Graphics2D) image.getGraphics();
        // 记录生成的文本
        StringBuilder sb = new StringBuilder();
        // 向图片中画指定个数字符
        for (int i = 0; i < this.textLength; i++) {
            String s = randomChar() + "";
            sb.append(s);
            // 字符的x坐标在[minX,maxX]范围内
            int cw = this.w / this.textLength;//每个字符占的宽度
            int minX = cw * i;
            int maxX = minX + cw * 2 / 3;
            int x = r.nextInt(maxX - minX + 1) + minX;
            //字符的y坐标在[minY,maxY]范围内
            Font font = randomFont();
            int minY = this.h * font.getSize() / 48;
            int maxY = this.h * font.getSize() * 3 / 80;
            minY = minY >= this.h ? this.h / 2 : minY;
            maxY = maxY >= this.h ? this.h * 9 / 10 : maxY;
            int y = r.nextInt(maxY - minY + 1) + minY;
            //字符旋转度数在[0,360']范围内
//            double rotate = Math.toRadians(30);//转换成theta值
//            g2.rotate(rotate, x + 12, y + 12);
            g2.setFont(font);
            g2.setColor(randomColor());
            g2.drawString(s, x, y);
        }
        return sb.toString();
    }
 
开发者ID:FlyingHe,项目名称:UtilsMaven,代码行数:37,代码来源:VerificationCodeImage.java

示例5: changeTickFontSize

import java.awt.Font; //导入方法依赖的package包/类
/**
 * Increases or decreases the tick font size.
 *
 * @param delta  the change in size.
 */
public void changeTickFontSize(int delta) {
    Font f = getTickLabelFont();
    String fName = f.getFontName();
    Font newFont = new Font(fName, f.getStyle(), (f.getSize() + delta));
    setTickLabelFont(newFont);
}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:12,代码来源:JThermometer.java

示例6: deriveFont

import java.awt.Font; //导入方法依赖的package包/类
/**
 * Workaround for Apple bug 3644261 - after using form editor, all boldface
 * fonts start showing up with incorrect metrics, such that all boldface
 * fonts in the entire IDE are displayed 12px below where they should be.
 * Embarrassing and awful.
 */
private static final Font deriveFont(Font f, int style) {
    //      return f.deriveFont(style);
    // see #49973 for details.
    Font result = Utilities.isMac() ? new Font(f.getName(), style, f.getSize()) : f.deriveFont(style);

    return result;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:14,代码来源:HtmlRenderer.java

示例7: sizeLabelFont

import java.awt.Font; //导入方法依赖的package包/类
private void sizeLabelFont(GLabel label, double width, double height) {
	int size, style;
	String name;
	Font f = label.getFont();
	name = f.getFontName();
	style = f.getStyle();
	size = f.getSize();
	while(label.getWidth() < width && label.getHeight() < height) {
		f = label.getFont();
		size = f.getSize();
		label.setFont(new Font(name, style, size+1));
	}
	label.setFont(new Font(name, style, size-1));
}
 
开发者ID:cookerlyk,项目名称:missile-defense,代码行数:15,代码来源:GButton.java

示例8: getFontTag

import java.awt.Font; //导入方法依赖的package包/类
private static HTMLTag getFontTag() {
    if (fontTag == null) {
        Font font = Options.getLabelFont();
        String face = font.getFamily();
        int size = font.getSize() - 2;
        // actually a slightly smaller font is more in line with
        // the edge font size, but then the forall symbol is not
        // available
        String argument = String.format("font-family:%s; font-size:%dpx", face, size);
        fontTag = createSpanTag(argument);
    }
    return fontTag;
}
 
开发者ID:meteoorkip,项目名称:JavaGraph,代码行数:14,代码来源:HTMLLineFormat.java

示例9: put

import java.awt.Font; //导入方法依赖的package包/类
/**
 * Converts the value to string using {@link Strings#toString(Object)}
 * method and then stores it.
 * There is get methods for values that are a String, an Integer, a Boolean,
 * a Font, a List of String and a Map of String*String.
 */
@Override
public Object put(Object key, Object value) {
  if(value instanceof Font){
    Font font = (Font)value;
    String family = font.getFamily();
    int size = font.getSize();
    boolean italic = font.isItalic();
    boolean bold = font.isBold();
    value = family + "#" + size + "#" + italic + "#" + bold;
  }
  return super.put(key.toString(), Strings.toString(value));
}
 
开发者ID:GateNLP,项目名称:gate-core,代码行数:19,代码来源:OptionsMap.java

示例10: toDisplayString

import java.awt.Font; //导入方法依赖的package包/类
@Override
public String toDisplayString(Font f) {
	if (f == null)
		return "???";
	return f.getFamily() + " " + FontUtil.toStyleDisplayString(f.getStyle()) + " " + f.getSize();
}
 
开发者ID:LogisimIt,项目名称:Logisim,代码行数:7,代码来源:Attributes.java

示例11: encode

import java.awt.Font; //导入方法依赖的package包/类
public static String encode(Font f) {
  return f.getName() + "," + f.getSize();
}
 
开发者ID:ajmath,项目名称:VASSAL-src,代码行数:4,代码来源:FontConfigurer.java

示例12: configureValue

import java.awt.Font; //导入方法依赖的package包/类
protected Object configureValue(Object value) {
    if (value instanceof Font) {
        Font font = (Font)value;
        if ("MS Sans Serif".equals(font.getName())) {
            int size = font.getSize();
            // 4950968: Workaround to mimic the way Windows maps the default
            // font size of 6 pts to the smallest available bitmap font size.
            // This happens mostly on Win 98/Me & NT.
            int dpi;
            try {
                dpi = Toolkit.getDefaultToolkit().getScreenResolution();
            } catch (HeadlessException ex) {
                dpi = 96;
            }
            if (Math.round(size * 72F / dpi) < 8) {
                size = Math.round(8 * dpi / 72F);
            }
            Font msFont = new FontUIResource("Microsoft Sans Serif",
                                  font.getStyle(), size);
            if (msFont.getName() != null &&
                msFont.getName().equals(msFont.getFamily())) {
                font = msFont;
            } else if (size != font.getSize()) {
                font = new FontUIResource("MS Sans Serif",
                                          font.getStyle(), size);
            }
        }

        if (FontUtilities.fontSupportsDefaultEncoding(font)) {
            if (!(font instanceof UIResource)) {
                font = new FontUIResource(font);
            }
        }
        else {
            font = FontUtilities.getCompositeFontUIResource(font);
        }
        return font;

    }
    return super.configureValue(value);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:42,代码来源:WindowsLookAndFeel.java

示例13: render

import java.awt.Font; //导入方法依赖的package包/类
@Override
public void render(BufferedImage image, String word) {
    final int width = image.getWidth();
    final int height = image.getHeight();
    Graphics2D graphics2D = image.createGraphics();

    RenderingHints hints = new RenderingHints(
            RenderingHints.KEY_ANTIALIASING,
            RenderingHints.VALUE_ANTIALIAS_ON);
    hints.add(new RenderingHints(RenderingHints.KEY_RENDERING,
            RenderingHints.VALUE_RENDER_QUALITY));
    graphics2D.setRenderingHints(hints);

    char[] wordChars = word.toCharArray();
    int wordLen = wordChars.length;

    Font[] chosenFonts = new Font[wordLen];
    int[] charWidths = new int[wordLen];
    int widthNeeded = 0;

    int maxFontSize = 0;

    for (int i = 0; i < wordLen; i++) {
        Font font = RandomUtil.rnd(fonts);

        if (font.getSize() > maxFontSize) {
            maxFontSize = font.getSize();
        }

        FontMetrics fontMetrics = graphics2D.getFontMetrics(font);
        int charWidth = fontMetrics.charWidth(wordChars[i]);
        widthNeeded = widthNeeded + charWidth;
        chosenFonts[i] = font;
        charWidths[i] = charWidth;
    }
    widthNeeded += charSpace * (wordLen - 1);

    int startPosX = (width - widthNeeded) / 2;
    int startPosY = (height - maxFontSize) / 5 + maxFontSize;

    for (int i = 0; i < wordLen; i++) {
        graphics2D.setFont(chosenFonts[i]);
        graphics2D.setColor(RandomUtil.rnd(colors));
        graphics2D.drawString(String.valueOf(wordChars[i]), startPosX, startPosY);
        startPosX = startPosX + charWidths[i] + charSpace;
    }
}
 
开发者ID:febit,项目名称:febit,代码行数:48,代码来源:DefaultWordRender.java

示例14: getFontSize

import java.awt.Font; //导入方法依赖的package包/类
public static int getFontSize(Font f){
	return f.getSize();
}
 
开发者ID:PhentixDevs,项目名称:PhySIX,代码行数:4,代码来源:FontUtil.java

示例15: getAAHintIntVal

import java.awt.Font; //导入方法依赖的package包/类
public static int getAAHintIntVal(Font2D font2D, Font font,
                                  FontRenderContext frc) {
    Object aa = frc.getAntiAliasingHint();
    if (aa == VALUE_TEXT_ANTIALIAS_OFF ||
        aa == VALUE_TEXT_ANTIALIAS_DEFAULT) {
        return INTVAL_TEXT_ANTIALIAS_OFF;
    } else if (aa == VALUE_TEXT_ANTIALIAS_ON) {
        return INTVAL_TEXT_ANTIALIAS_ON;
    } else if (aa == VALUE_TEXT_ANTIALIAS_GASP) {
        /* FRC.isIdentity() would have been useful */
        int ptSize;
        AffineTransform tx = frc.getTransform();
        if (tx.isIdentity() && !font.isTransformed()) {
            ptSize = font.getSize();
        } else {
            /* one or both transforms is not identity */
            float size = font.getSize2D();
            if (tx.isIdentity()) {
                tx = font.getTransform();
                tx.scale(size, size);
            } else {
                tx.scale(size, size);
                if (font.isTransformed()) {
                    tx.concatenate(font.getTransform());
                }
            }
            double shearx = tx.getShearX();
            double scaley = tx.getScaleY();
            if (shearx != 0) {
                scaley = Math.sqrt(shearx * shearx + scaley * scaley);
            }
            ptSize = (int)(Math.abs(scaley)+0.5);
        }
        if (font2D.useAAForPtSize(ptSize)) {
            return INTVAL_TEXT_ANTIALIAS_ON;
        } else {
            return INTVAL_TEXT_ANTIALIAS_OFF;
        }
    } else if (aa == VALUE_TEXT_ANTIALIAS_LCD_HRGB ||
               aa == VALUE_TEXT_ANTIALIAS_LCD_HBGR) {
        return INTVAL_TEXT_ANTIALIAS_LCD_HRGB;
    } else if (aa == VALUE_TEXT_ANTIALIAS_LCD_VRGB ||
               aa == VALUE_TEXT_ANTIALIAS_LCD_VBGR) {
        return INTVAL_TEXT_ANTIALIAS_LCD_VRGB;
    } else {
        return INTVAL_TEXT_ANTIALIAS_OFF;
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:49,代码来源:FontStrikeDesc.java


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