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


Java Font.createFont方法代码示例

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


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

示例1: getBelwe

import java.awt.Font; //导入方法依赖的package包/类
public static Font getBelwe(int size) {
    try {
        Font font = Font.createFont(Font.TRUETYPE_FONT, Fontes.class.getResourceAsStream("/com/limagiran/hearthstone/util/belwe.ttf"));
        font = font.deriveFont(Font.BOLD, size);
        return font;
    } catch (Exception ex) {
    }
    return new Font("Tahoma", Font.BOLD, size);
}
 
开发者ID:limagiran,项目名称:hearthstone,代码行数:10,代码来源:Fontes.java

示例2: IconFactory

import java.awt.Font; //导入方法依赖的package包/类
/**
 * Creates the icon factory
 */
public IconFactory() {
    try {
        fontAwesome = Font.createFont(Font.TRUETYPE_FONT, IconFactory.class.getResourceAsStream("/fontawesome-webfont.ttf"));
    } catch (Exception e) {
        ExceptionHandler.get().handle(e);
    }
    mapping = loadMapings();
}
 
开发者ID:VISNode,项目名称:VISNode,代码行数:12,代码来源:IconFactory.java

示例3: updateFont

import java.awt.Font; //导入方法依赖的package包/类
private void updateFont()
{
	try
	{
		Font mcfont = Font.createFont(Font.TRUETYPE_FONT,
			this.getClass().getClassLoader()
				.getResourceAsStream("assets/minecraft/font/mcfont.ttf"));
		mcfont = mcfont.deriveFont(12F);
		Font defaultFont = new Font("Monospaced", Font.PLAIN, 14);
		spamArea.setFont(wurst.options.spamFont ? mcfont : defaultFont);
	}catch(Exception e1)
	{
		e1.printStackTrace();
	}
}
 
开发者ID:Wurst-Imperium,项目名称:Wurst-MC-1.12,代码行数:16,代码来源:SpammerMod.java

示例4: registerFont

import java.awt.Font; //导入方法依赖的package包/类
public static boolean registerFont(File fontFile) {
    boolean b = false;
    try {
        Font f = Font.createFont(Font.TRUETYPE_FONT, fontFile);
        GraphicsEnvironment.getLocalGraphicsEnvironment().registerFont(f);
        b = true;
    } catch (FontFormatException | IOException e) {
        b = false;
    }
    return b;
}
 
开发者ID:isu3ru,项目名称:java-swing-template,代码行数:12,代码来源:Utilities.java

示例5: loadResources

import java.awt.Font; //导入方法依赖的package包/类
public static void loadResources() {
	try(InputStream mainFontIn = FontResources.class.getClassLoader().getResourceAsStream("hyperbox/mafia/resources/fonts/ubuntu.ttf");
			InputStream mainFontBoldIn = FontResources.class.getClassLoader().getResourceAsStream("hyperbox/mafia/resources/fonts/ubuntuBold.ttf")) {
		
		mainFont = Font.createFont(Font.TRUETYPE_FONT, mainFontIn);
		mainFontBold = Font.createFont(Font.TRUETYPE_FONT, mainFontBoldIn);
		
		
		GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
		
		ge.registerFont(mainFont);
		ge.registerFont(mainFontBold);
	} catch (IOException | FontFormatException e) {
		e.printStackTrace();
		System.exit(-1);
	}
}
 
开发者ID:ProjectK47,项目名称:Mafia,代码行数:18,代码来源:FontResources.java

示例6: tryLoadFontFromFile

import java.awt.Font; //导入方法依赖的package包/类
/**
 * Will try to load a font from the specified ttf file.
 * If successful, will correctly set drawing attributes.
 * Otherwise will output an error, but will not halt the program.
 * @param fName ttf file to load from.
 */
private void tryLoadFontFromFile(String fName) {
  try {
    Font temp = Font.createFont(Font.TRUETYPE_FONT, new FileInputStream(fName));
    fontName = fName;
    dFont = temp;
    loadedFonts.add(temp);
    loadedFiles.add(fName);
  }
  catch (Exception e) {
    e.printStackTrace();
    System.out.println("ERROR: EZText was unable to load a text from the specified file:" + fName);
    System.out.println("  The change will not be applied.");
  }
}
 
开发者ID:gcalica,项目名称:agar.io,代码行数:21,代码来源:EZ.java

示例7: getFont

import java.awt.Font; //导入方法依赖的package包/类
private static Font getFont(String name, int size) {
	try {
		InputStream in = FlagInfoPanel.class.getResourceAsStream(name);
		Font font = Font.createFont(Font.TRUETYPE_FONT, in);
		return font.deriveFont((float)size);
	} catch (Exception e) {
		return null;
	}
}
 
开发者ID:kreativekorp,项目名称:vexillo,代码行数:10,代码来源:FlagInfoPanel.java

示例8: LoginPage

import java.awt.Font; //导入方法依赖的package包/类
/**
 * Creates new form LoginPage
 */
public LoginPage() throws Exception {
    initComponents();
    logoSetup();
    try {   
        InputStream is = LoginPage.class.getResourceAsStream("cac_champagne.ttf");
        Font cac_champagne = Font.createFont(Font.TRUETYPE_FONT, is);
        jLabel1.setFont(cac_champagne.deriveFont(Font.PLAIN, 48f)); // NOI18N
        jLabel1.setForeground(new java.awt.Color(239, 239, 239));
        jLabel1.setText("fodder");
        is = LoginPage.class.getResourceAsStream("DAGGERSQUARE.otf");
        Font DAGGERSQUARE = Font.createFont(Font.TRUETYPE_FONT, is);
        jLabel5.setFont(DAGGERSQUARE.deriveFont(Font.PLAIN, 36f)); // NOI18N
        jLabel5.setForeground(new java.awt.Color(101, 43, 215));
        jLabel5.setText("Login");
    } catch(IOException | FontFormatException e) {
        System.out.println("Font not found");
    }
    Color borderColor = new Color(179, 193, 193);
    jPanel1.setBorder(BorderFactory.createMatteBorder(0, 0, 2, 0, Color.WHITE));
    username1.setBorder(BorderFactory.createMatteBorder(0, 0, 2, 0, borderColor));
    password1.setBorder(BorderFactory.createMatteBorder(0, 0, 2, 0, borderColor));
    password1.setEchoChar((char)0);
    password1.setText("Password");
    usernameRegistration.setBorder(BorderFactory.createMatteBorder(0, 0, 2, 0, borderColor));
    password_registartion.setBorder(BorderFactory.createMatteBorder(0, 0, 2, 0, borderColor));
    password_registartion.setEchoChar((char)0);
    password_registartion.setText("Password");
    name.setBorder(BorderFactory.createMatteBorder(0, 0, 2, 0, borderColor));
    email.setBorder(BorderFactory.createMatteBorder(0, 0, 2, 0, borderColor));
    this.setLocationRelativeTo(null);
}
 
开发者ID:himank-goel,项目名称:Fodder-OOM_Project,代码行数:35,代码来源:LoginPage.java

示例9: FontResource

import java.awt.Font; //导入方法依赖的package包/类
/**
 * Do not use directly.
 *
 * @param resourceLocator The {@code URI} used when loading this
 *     resource.
 * @exception IOException if unable to read the font.
 */
public FontResource(URI resourceLocator) throws IOException {
    super(resourceLocator);
    font = null;
    try {
        if (resourceLocator.getPath() != null
            && resourceLocator.getPath().endsWith(".ttf")) {
            URL url = resourceLocator.toURL();
            font = Font.createFont(Font.TRUETYPE_FONT, url.openStream());
        } else {
            String name = resourceLocator.getSchemeSpecificPart();
            font = Font.decode(name.substring(SCHEME.length()));
        }

        if (font != null) {
            GraphicsEnvironment.getLocalGraphicsEnvironment()
                .registerFont(font);
        }

        logger.info("Loaded font: " + font.getFontName()
            + " from: " + resourceLocator);
    } catch (FontFormatException|IOException ex) {
        logger.log(Level.WARNING,
            "Failed loading font from: " + resourceLocator, ex);
        throw new IOException(ex.getMessage());
    }
}
 
开发者ID:FreeCol,项目名称:freecol,代码行数:34,代码来源:FontResource.java

示例10: main

import java.awt.Font; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception
{
    // The bug only happens with Type 1 fonts. The Ghostscript font files
    // should be commonly available. From distro pacakge or
    //  ftp://ftp.gnu.org/gnu/ghostscript/gnu-gs-fonts-other-6.0.tar.gz
    // Pass pfa/pfb font file as argument
    String path = args[0];

    // Load
    InputStream stream = new FileInputStream(path);
    Font font = Font.createFont(Font.TYPE1_FONT,stream);

    // Ensure native bits have been generated
    BufferedImage img = new BufferedImage(100,100,
                             BufferedImage.TYPE_INT_ARGB);
    Graphics2D g2d = img.createGraphics();
    FontRenderContext frc = g2d.getFontRenderContext();

    font.getLineMetrics("derp",frc);

    // Force disposal -
    // System.gc() is not sufficient.
    Field font2DHandleField = Font.class.getDeclaredField("font2DHandle");
    font2DHandleField.setAccessible(true);
    sun.font.Font2DHandle font2DHandle =
                  (sun.font.Font2DHandle)font2DHandleField.get(font);

    sun.font.Font2D font2D = font2DHandle.font2D;
    sun.font.Type1Font type1Font = (sun.font.Type1Font)font2D;

    Method getScalerMethod =
    sun.font.Type1Font.class.getDeclaredMethod("getScaler");
    getScalerMethod.setAccessible(true);
    sun.font.FontScaler scaler =
              (sun.font.FontScaler)getScalerMethod.invoke(type1Font);

    // dispose should not crash due to double free
    scaler.dispose();
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:40,代码来源:FontDisposeTest.java

示例11: writeImage

import java.awt.Font; //导入方法依赖的package包/类
public static void writeImage(File fontFile, File outputFile, String value) throws Exception {
    BufferedImage image = new BufferedImage(200, 200, BufferedImage.TYPE_INT_RGB);
    Graphics2D g = image.createGraphics();
    g.setColor(Color.WHITE);
    g.fillRect(0, 0, image.getWidth(), image.getHeight());
    g.setColor(Color.BLACK);

    Font font = Font.createFont(Font.TRUETYPE_FONT, fontFile);
    font = font.deriveFont(Font.PLAIN, 72f);
    FontRenderContext frc = new FontRenderContext(null, false, false);
    GlyphVector gv = font.createGlyphVector(frc, value);
    g.drawGlyphVector(gv, 10, 80);
    g.fill(gv.getOutline(10, 180));
    ImageIO.write(image, "png", outputFile);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:16,代码来源:GlyphVectorOutline.java

示例12: createFont

import java.awt.Font; //导入方法依赖的package包/类
public static TrueTypeFont createFont(ResourceLocation res, float defSize, boolean antialias, int type, char[] additionalChars) {
    Font font;
    TrueTypeFont out = null;
    try {
        font = Font.createFont(type, Minecraft.getMinecraft().getResourceManager().getResource(res).getInputStream());
        font = font.deriveFont(defSize);
        out = new TrueTypeFont(font, antialias, additionalChars);
    } catch (Exception e) {
        e.printStackTrace();
    }
    return out;
}
 
开发者ID:McJty,项目名称:Lector,代码行数:13,代码来源:FontLoader.java

示例13: FontData

import java.awt.Font; //导入方法依赖的package包/类
/**
 * Create a new font data element
 * 
 * @param ttf The TTF file to read
 * @param size The size of the new font
 * @throws IOException Indicates a failure to 
 */
private FontData(InputStream ttf, float size) throws IOException {
	if (ttf.available() > MAX_FILE_SIZE) {
		throw new IOException("Can't load font - too big");
	}
	byte[] data = IOUtils.toByteArray(ttf);
	if (data.length > MAX_FILE_SIZE) {
		throw new IOException("Can't load font - too big");
	}
	
	this.size = size;
	try {
		javaFont = Font.createFont(Font.TRUETYPE_FONT, new ByteArrayInputStream(data));
		TTFFile rawFont = new TTFFile();
		if (!rawFont.readFont(new FontFileReader(data))) {
			throw new IOException("Invalid font file");
		}
		upem = rawFont.getUPEM();
		ansiKerning = rawFont.getAnsiKerning();
		charWidth = rawFont.getAnsiWidth();
		fontName = rawFont.getPostScriptName();
		familyName = rawFont.getFamilyName();
		
		String name = getName();
		System.err.println("Loaded: "+name+" ("+data.length+")");
		boolean bo = false;
		boolean it = false;
		if (name.indexOf(',') >= 0) {
			name = name.substring(name.indexOf(','));
		
			if (name.indexOf("Bold") >= 0) {
				bo = true;
			}
			if (name.indexOf("Italic") >= 0) {
				it = true;
			}
		}
		
		if ((bo & it)) {
			javaFont = javaFont.deriveFont(Font.BOLD | Font.ITALIC);
		} else if (bo) {
			javaFont = javaFont.deriveFont(Font.BOLD);
		} else if (it) {
			javaFont = javaFont.deriveFont(Font.ITALIC);
		}
	} catch (FontFormatException e) {
		IOException x = new IOException("Failed to read font");
		x.initCause(e);
		throw x;
	}
}
 
开发者ID:j-dong,项目名称:trashjam2017,代码行数:58,代码来源:FontData.java

示例14: SwingFrame

import java.awt.Font; //导入方法依赖的package包/类
/**
 * Public constructor.
 *
 * @param screen the Screen that Backend talks to
 */
public SwingFrame(final SwingScreen screen) {
    this.screen = screen;
    setDOSColors();

    // Figure out my cursor style
    String cursorStyleString = System.getProperty(
        "jexer.Swing.cursorStyle", "underline").toLowerCase();

    if (cursorStyleString.equals("underline")) {
        cursorStyle = CursorStyle.UNDERLINE;
    } else if (cursorStyleString.equals("outline")) {
        cursorStyle = CursorStyle.OUTLINE;
    } else if (cursorStyleString.equals("block")) {
        cursorStyle = CursorStyle.BLOCK;
    }

    if (System.getProperty("jexer.Swing.tripleBuffer") != null) {
        if (System.getProperty("jexer.Swing.tripleBuffer").
            equals("false")) {

            SwingScreen.tripleBuffer = false;
        }
    }

    setTitle("Jermit");
    setBackground(Color.black);

    try {
        // Always try to use Terminus, the one decent font.
        ClassLoader loader = Thread.currentThread().
                getContextClassLoader();
        InputStream in = loader.getResourceAsStream(FONTFILE);
        Font terminusRoot = Font.createFont(Font.TRUETYPE_FONT, in);
        Font terminus = terminusRoot.deriveFont(Font.PLAIN, 20);
        setFont(terminus);
        gotTerminus = true;
    } catch (Exception e) {
        e.printStackTrace();
        // setFont(new Font("Liberation Mono", Font.PLAIN, 24));
        setFont(new Font(Font.MONOSPACED, Font.PLAIN, 24));
    }
    pack();

    // Kill the X11 cursor
    // Transparent 16 x 16 pixel cursor image.
    BufferedImage cursorImg = new BufferedImage(16, 16,
        BufferedImage.TYPE_INT_ARGB);
    // Create a new blank cursor.
    Cursor blankCursor = Toolkit.getDefaultToolkit().createCustomCursor(
        cursorImg, new Point(0, 0), "blank cursor");
    setCursor(blankCursor);

    // Be capable of seeing Tab / Shift-Tab
    setFocusTraversalKeysEnabled(false);

    // Save the text cell width/height
    getFontDimensions();

    // Cache glyphs as they are rendered
    glyphCacheBlink = new HashMap<Cell, BufferedImage>();
    glyphCache = new HashMap<Cell, BufferedImage>();

    // Setup triple-buffering
    if (SwingScreen.tripleBuffer) {
        setIgnoreRepaint(true);
        createBufferStrategy(3);
        bufferStrategy = getBufferStrategy();
    }
}
 
开发者ID:klamonte,项目名称:jermit,代码行数:75,代码来源:SwingScreen.java

示例15: Instructions

import java.awt.Font; //导入方法依赖的package包/类
public Instructions(JFrame f, int frameBoundX, int frameBoundY) {
	
	// Font
	InputStream is = Menu.class.getResourceAsStream("Cheap Potatoes.ttf");
	try {
		font = Font.createFont(Font.TRUETYPE_FONT, is);
	} catch (FontFormatException | IOException e1) {
		// TODO Auto-generated catch
		// block
		e1.printStackTrace();
	}
	
	//Main Panel of Instructions Section created here
	JPanel instrPanel = new JPanel();
	instrPanel.setLayout(null);
	setBounds(0,0,frameBoundX, frameBoundY);
	
	//Logo
	JLabel logoLabel = new JLabel("GEOTRIX", SwingConstants.CENTER);
	sizedFont = font.deriveFont(68f);
	logoLabel.setFont(sizedFont);
	logoLabel.setBounds(frameBoundX / 2 - 200, (frameBoundY-520)/ 2, 400, 190);
	
	JButton backButton = new JButton("Back");
	backButton.setBorderPainted(false);
	backButton.setFocusPainted(false);
	backButton.setContentAreaFilled(false);
	sizedFont = font.deriveFont(Font.BOLD, 30f);
	backButton.setFont(sizedFont);
	backButton.setForeground(Color.RED);
	backButton.setBounds(10, 10, 200, 100);
	// when backButton clicked
	backButton.addActionListener(new ActionListener() {
		public void actionPerformed(ActionEvent e) {
			//remove panel
			instrPanel.setVisible(false);
			f.remove(instrPanel);
			new MainMenu(f, frameBoundX, frameBoundY);
		}
	});
	
	//Logo
	JLabel instructionLabel = new JLabel("Arrow keys + Space button", SwingConstants.CENTER);
	sizedFont = font.deriveFont(40f);
	instructionLabel.setFont(sizedFont);
	instructionLabel.setBounds(25, frameBoundY/2 - 100, frameBoundX - 50, 200);
	instrPanel.add(instructionLabel);

	//Background Icon
	String img = "background_revision.jpg";
	ImageIcon imgIc = new ImageIcon(this.getClass().getResource(img));
	
	//Backgroud Label
	JLabel bgLabel = new JLabel(imgIc);
	bgLabel.setBounds(0, 0, frameBoundX, frameBoundY);

	instrPanel.add(backButton);
	instrPanel.add(logoLabel);
	instrPanel.add(bgLabel);
	
	f.add(instrPanel);
	f.revalidate();
	f.setVisible(true);
	
	
}
 
开发者ID:berkunal,项目名称:SWEngProject,代码行数:67,代码来源:Instructions.java


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