2011-03-03 7 views
0
public class TestEye extends MainScreen { 

    LabelField l1,l2; 
    RichTextField rch; 
    VerticalFieldManager vfm; 
    Font myfont1; 
    String word[]={"F D","N P","U H","F Z","K R","U V","Z E","E K","P Z","V N"}; 

public TestEye() 
{ 
     vfm=new VerticalFieldManager(VerticalFieldManager.USE_ALL_WIDTH|VerticalFieldManager.USE_ALL_HEIGHT) 
      { 
      protected void paint(Graphics graphics) 
         { 
          graphics.setColor(Color.BLACK); 
          graphics.fillRect(0, 0, Display.getHorizontalResolution(), Display.getVerticalResolution()); 
          super.paint(graphics); 
         } 
      }; 
     l1=new LabelField("----------------",Field.USE_ALL_WIDTH|Field.USE_ALL_HEIGHT); 
     l2=new LabelField("----------------",Field.USE_ALL_WIDTH|Field.USE_ALL_HEIGHT); 
     rch=new RichTextField() 
      { 


       public void paint(Graphics g) 
       { 
         g.setBackgroundColor(Color.BLACK); 
         g.setColor(Color.WHITE); 
          super.paint(g); 
       } 
      }; 
     vfm.add(l1); 
     vfm.add(l2); 
     vfm.add(rch); 
     add(vfm); 
     System.out.println("::::::::::::::::end test eye:::::::::::::::"); 
     push(word); 
    } 

    public void push(final String arr1[]) { 

     new Thread(new Runnable() 
     { 
      public void run() 
      { 
         int k=20; 
        for(int i=0;i<10;i++) 
         { 
          try 
           {  
            String data=arr1[i]; 
            Font myfont1=Font.getDefault().derive(Font.PLAIN,k); 
            rch.setFont(myfont1); 
            rch.setText("      "+(data)); 
            k=k-2; 
           } 
          catch(Exception ex) 
           { 
            ex.printStackTrace(); 
           } 
          try 
           { 
            Thread.sleep(2000); 
           } 
          catch (InterruptedException e) 
           { 
            e.printStackTrace(); 
           } 
         } 


       } 

     }).start(); 
    } 
} 

Je dois réduire la taille de la police pour chaque mot utilisé dans le tableau String.
ceci est mon code mais ici à l'intérieur pour la boucle la police ne fonctionne pas alors veuillez la vérifier et me donner quelques suggestions merciComment réduire la taille de la police?

Répondre

0

Vous définissez la police pour le champ entier dans votre boucle. Si vous souhaitez que différentes parties du contenu du champ soient dans des polices différentes, ce n'est pas la manière de le faire. Jetez un oeil aux docs pour RichTextField pour savoir comment utiliser les méthodes multi-arguments setText pour définir différentes polices pour différentes parties du texte.

2

vous pouvez essayer ActiveRichTextField. dans ActiveRichTextField non seulement vous pouvez donner des polices différentes, vous pouvez également donner des couleurs différentes.

par exemple.

String data = "Hello World!"; 
int offsets[] ={0,5,data.length()}; 
Font[] fonts = new Font[] { Font.getDefault(), Font.getDefault()}; 
int bg[] = new int[] { Color.WHITE, Color.WHITE}; 
int fg[] = new int[] { Color.BLACK, Color.RED}; 
byte attributes[] = {0,1}; 

add(new ActiveRichTextField(data, offsets, attributes, fonts, 
           fg, bg, 0)); 
Questions connexes