2013-05-29 24 views
0

我一直在计划制作一款字体更改器应用程序,以最终放在我的手机上。但目前我遇到了一些困难,因为某些字体不起作用。我认为这可能是我的代码。我可能会错过一些东西,因为我看到另一个字体转换器代码,它的工作完美。所以我想知道的是为什么没有这些字体中的一些工作。是否有我想要打电话的某种方法?我做了一些研究,发现我不得不使用import java.awt.Font;这使得某些字体有效。我可以添加自定义字体(我会稍后),但我想让我的电脑上可用的所有字体在此应用程序中工作。字体更改器应用程序。有些字体无法正常工作

这里是我的代码:

import java.awt.*; 
import java.awt.Font.*; 
import java.awt.event.*; 
import java.applet.Applet; 

public class FontChangerForAndroid extends Applet implements ActionListener 
    { 

    Button Change; 
    Button TestOutput; 
    Choice Fonts; 
    TextField TestTxt; 
    Label text; 
    /*** 
    * Okay, this works so far. Not sure if the comic one isnt working. Or if I just spelled it wrong. I will have to 
    * look it up in a java Font libaray. 
    * 
    * I basically want to make this a function on my entire phone. So i'll have to change it to an android app. 
    * (I hope it has the Rosemarry font) 
    * While I'm practicing with this app, I'll add a text box that will let me change the label. Or enter the words 
    * in the app. 
    * 
    */ 
    public void init(){ 

     setLayout(new FlowLayout()); 
     Fonts = new Choice(); 
     //Some fonts don't work because we I don't know what fonts are in the JGE. Working on how to find them 
     //Will just add fonts to this system if possible. 
     Fonts.addItem("Dialog"); 
     Fonts.addItem("Serif"); 
     Fonts.addItem("SansSerif"); 
     Fonts.addItem("Monospaced"); 
     Fonts.addItem("DialogInput"); 
     Fonts.addItem("Calist"); 
     Fonts.addItem("Centbi"); 

     add(Fonts); 
     TestTxt = new TextField("Enter Text",15); 
     add(TestTxt); 
     TestOutput = new Button("Enter"); 
     add(TestOutput); 
     Change = new Button("Change Font"); 
     add(Change); 
     text = new Label("Real eye realize real lies"); 
     add(text); 

     Change.addActionListener(this); 
     TestOutput.addActionListener(this); 
    } 

    public void actionPerformed(ActionEvent evt) { 
     String item = (String) Fonts.getSelectedItem(); 
     //Gets the selected option from the list and sets the text as the Font. 
     if (evt.getSource() == Change){ 
     text.setFont(new Font(item, Font.PLAIN, 12)); 
     } 
     //In this section you can enter something and print it out on the screen. 
     if (evt.getSource() == TestOutput){ 
     repaint(); 
     } 
    } 


    /** 
    * I'm trying to figure out what code goes here in order for the font to change here also....5/22/13 
    * 
    */ 
    public void paint (Graphics g){ 
    //String item = Fonts.getSelectedItem(); 
    //g.setFont(TestTxt.setFont(new Font(item, Font.PLAIN, 12))); 
    g.drawString(TestTxt.getText(),20,100); 

    } 
} 

回答

1

有在GraphicsEnvironment的方法称为registerFont。例如。如在this answer中所见。

+0

你能给我一个关于registerFont方法如何工作的例子吗? – user2433219

+0

我也从这个应用程序中采取了一些方法,仅仅因为它们对于更大的图像是无用的。 – user2433219

+0

有关示例,请参见[此答案](http://stackoverflow.com/a/8365030/418556)。 –

相关问题