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


Java Font.SERIF属性代码示例

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


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

示例1: paint

@Override
public void paint(){
	// Compute maximum width of text we're going to draw
	TextRenderer textRenderer = new TextRenderer(new Font(Font.SERIF,0 , 18));
	
    int maxTextWidth = (int) textRenderer.getBounds(this.text).getWidth();
    maxTextWidth = Math.min(maxTextWidth+10,size.width);
	
	GL2 gl=glContext.getGL2();
	gl.glClear(GL.GL_COLOR_BUFFER_BIT);
	gl.glPolygonMode (GL2.GL_FRONT, GL2.GL_LINE_STRIP);
    gl.glColor3f(0.5f, 0.5f, 0.5f);

    gl.glBegin(GL2.GL_LINE_STRIP);
    gl.glVertex2i( this.posx,this.posy);							//x1,y1
    gl.glVertex2i( this.posx+maxTextWidth,this.posy );				//x2,y1
    gl.glVertex2i( this.posx+maxTextWidth,this.posy +size.height); 	//x2,y2 
    gl.glVertex2i( this.posx,this.posy+size.height);				//x1,y2
    gl.glVertex2i( this.posx,this.posy);	
    gl.glEnd( );
    
    
    GLDrawable draw=gl.getGL().getContext().getGLDrawable();
	textRenderer.beginRendering(draw.getWidth(),draw.getHeight());
	textRenderer.setColor(Color.WHITE);
	textRenderer.setSmoothing(true);
	textRenderer.draw(this.text,(int)posx,(int)posy+5); //text and position
	textRenderer.flush();
	textRenderer.endRendering();
	
	gl.glFlush();
}
 
开发者ID:ec-europa,项目名称:sumo,代码行数:32,代码来源:GLButton.java

示例2: makeText

private static void makeText(Graphics2D graphics, ImageSize maxSize, Random rand) {
	switchColor(graphics, rand);
	
	String fontName = Font.SANS_SERIF;
	switch (rand.nextInt(4)) {
		case 0: fontName = Font.SANS_SERIF; break;
		case 1: fontName = Font.MONOSPACED; break;
		case 2: fontName = Font.SERIF; break;
		case 3: fontName = Font.DIALOG; break;
	}
	
	int fontStyle = Font.PLAIN;
	switch (rand.nextInt(3)) {
		case 0: fontStyle = Font.PLAIN; break;
		case 1: fontStyle = Font.BOLD; break;
		case 2: fontStyle = Font.ITALIC; break;
	}
	
	int fontSize = rand.nextInt(MAX_FONT_SIZE + 1);
	
	graphics.setFont(new Font(fontName, fontStyle, fontSize));
	
	int textLength = rand.nextInt(MAX_TEXT_LENGTH + 1);
	String str = Stream.generate(() -> rand.nextInt(MAX_CHAR_SIZE))
			.limit(textLength)
			.map(i -> (char)i.intValue())
			.collect(StringBuilder::new, StringBuilder::append, StringBuilder::append).toString();
	
	graphics.drawString(str, rand.nextInt(maxSize.getWidth()), rand.nextInt(maxSize.getHeight()));
}
 
开发者ID:DescartesResearch,项目名称:Pet-Supply-Store,代码行数:30,代码来源:ImageCreator.java

示例3: getInstalledFontFamilyNames

/**
 * Get a list of installed fonts in the requested {@link Locale}.
 * The list contains the fonts Family Names.
 * If Locale is null, the default locale is used.
 *
 * @param requestedLocale, if null the default locale is used.
 * @return list of installed fonts in the system.
 */
public String[] getInstalledFontFamilyNames(Locale requestedLocale) {
    if (requestedLocale == null) {
        requestedLocale = Locale.getDefault();
    }
    if (allFamilies != null && lastDefaultLocale != null &&
        requestedLocale.equals(lastDefaultLocale)) {
            String[] copyFamilies = new String[allFamilies.length];
            System.arraycopy(allFamilies, 0, copyFamilies,
                             0, allFamilies.length);
            return copyFamilies;
    }

    TreeMap<String,String> familyNames = new TreeMap<String,String>();
    //  these names are always there and aren't localised
    String str;
    str = Font.SERIF;         familyNames.put(str.toLowerCase(), str);
    str = Font.SANS_SERIF;    familyNames.put(str.toLowerCase(), str);
    str = Font.MONOSPACED;    familyNames.put(str.toLowerCase(), str);
    str = Font.DIALOG;        familyNames.put(str.toLowerCase(), str);
    str = Font.DIALOG_INPUT;  familyNames.put(str.toLowerCase(), str);

    /* Platform APIs may be used to get the set of available family
     * names for the current default locale so long as it is the same
     * as the start-up system locale, rather than loading all fonts.
     */
    if (requestedLocale.equals(getSystemStartupLocale()) &&
        getFamilyNamesFromPlatform(familyNames, requestedLocale)) {
        /* Augment platform names with JRE font family names */
        getJREFontFamilyNames(familyNames, requestedLocale);
    } else {
        loadFontFiles();
        Font2D[] physicalfonts = getPhysicalFonts();
        for (int i=0; i < physicalfonts.length; i++) {
            if (!(physicalfonts[i] instanceof NativeFont)) {
                String name =
                    physicalfonts[i].getFamilyName(requestedLocale);
                familyNames.put(name.toLowerCase(requestedLocale), name);
            }
        }
    }

    // Add any native font family names here
    addNativeFontFamilyNames(familyNames, requestedLocale);

    String[] retval =  new String[familyNames.size()];
    Object [] keyNames = familyNames.keySet().toArray();
    for (int i=0; i < keyNames.length; i++) {
        retval[i] = (String)familyNames.get(keyNames[i]);
    }
    if (requestedLocale.equals(Locale.getDefault())) {
        lastDefaultLocale = requestedLocale;
        allFamilies = new String[retval.length];
        System.arraycopy(retval, 0, allFamilies, 0, allFamilies.length);
    }
    return retval;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:64,代码来源:SunFontManager.java

示例4: getInstalledFontFamilyNames

/**
 * Get a list of installed fonts in the requested {@link Locale}.
 * The list contains the fonts Family Names.
 * If Locale is null, the default locale is used.
 *
 * @param requestedLocale, if null the default locale is used.
 * @return list of installed fonts in the system.
 */
public String[] getInstalledFontFamilyNames(Locale requestedLocale) {
    if (requestedLocale == null) {
        requestedLocale = Locale.getDefault();
    }
    if (allFamilies != null && lastDefaultLocale != null &&
        requestedLocale.equals(lastDefaultLocale)) {
            String[] copyFamilies = new String[allFamilies.length];
            System.arraycopy(allFamilies, 0, copyFamilies,
                             0, allFamilies.length);
            return copyFamilies;
    }

    TreeMap<String,String> familyNames = new TreeMap<String,String>();
    //  these names are always there and aren't localised
    String str;
    str = Font.SERIF;         familyNames.put(str.toLowerCase(), str);
    str = Font.SANS_SERIF;    familyNames.put(str.toLowerCase(), str);
    str = Font.MONOSPACED;    familyNames.put(str.toLowerCase(), str);
    str = Font.DIALOG;        familyNames.put(str.toLowerCase(), str);
    str = Font.DIALOG_INPUT;  familyNames.put(str.toLowerCase(), str);

    /* Platform APIs may be used to get the set of available family
     * names for the current default locale so long as it is the same
     * as the start-up system locale, rather than loading all fonts.
     */
    if (requestedLocale.equals(getSystemStartupLocale()) &&
        getFamilyNamesFromPlatform(familyNames, requestedLocale)) {
        /* Augment platform names with JRE font family names */
        getJREFontFamilyNames(familyNames, requestedLocale);
    } else {
        loadFontFiles();
        Font2D[] physicalfonts = getPhysicalFonts();
        for (int i=0; i < physicalfonts.length; i++) {
            if (!(physicalfonts[i] instanceof NativeFont)) {
                String name =
                    physicalfonts[i].getFamilyName(requestedLocale);
                familyNames.put(name.toLowerCase(requestedLocale), name);
            }
        }
    }

    // Add any native font family names here
    addNativeFontFamilyNames(familyNames, requestedLocale);

    String[] retval =  new String[familyNames.size()];
    Object [] keyNames = familyNames.keySet().toArray();
    for (int i=0; i < keyNames.length; i++) {
        retval[i] = familyNames.get(keyNames[i]);
    }
    if (requestedLocale.equals(Locale.getDefault())) {
        lastDefaultLocale = requestedLocale;
        allFamilies = new String[retval.length];
        System.arraycopy(retval, 0, allFamilies, 0, allFamilies.length);
    }
    return retval;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:64,代码来源:SunFontManager.java


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