[an error occurred while processing this directive]

Different Size of Font MIDlet Example

                         

This example simply shows the different size of font. There are three attributes are used for the different font sizes. That are:

  • Font.SIZE_LARGE);

  • Font.SIZE_MEDIUM);  

  • Font.SIZE_SMALL);   

The SIZE_LARGE is used to large size of font, the SIZE_MEDIUM is used to medium size of font and the SIZE_SMALL is used to small size of font, which shows in the mobile figure below:

 

 

Source Code of FontSize.java

 

import java.io.*;
import java.lang.*;
import javax.microedition.io.*;
import javax.microedition.rms.*;
import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;  

public class FontSize extends MIDlet {
  public static final boolean COLOR = false;
  public static final boolean DEBUG = false;
  private Display display = null;
  private FontCanvas fontCanvas = null;
  private boolean painting = false;

  public FontSize() {        
    display = Display.getDisplay(this);
        fontCanvas = new FontCanvas(this);
  }

  public void startApp() throws MIDletStateChangeException 
    display.setCurrent(fontCanvas);
  }

  public void pauseApp() {}

  protected void destroyApp(boolean unconditionalthrows 
                                 MIDletStateChangeException {}

  class FontCanvas extends Canvas {
    private FontSize parent = null;
    private int width = getWidth();
        private int height = getHeight();

    public FontCanvas(FontSize parent) {
      this.parent = parent;
    }

    public void paint(Graphics g) {
      g.setColor(2551280);  
            g.fillRect(00, width, height);
            Font font1 = Font.getFont(Font.FACE_SYSTEM, Font.STYLE_PLAIN, 
            Font.SIZE_LARGE
);  

            Font font2 = Font.getFont(Font.FACE_SYSTEM, Font.STYLE_PLAIN, 
            Font.SIZE_MEDIUM
);  

            Font font3 = Font.getFont(Font.FACE_SYSTEM, Font.STYLE_PLAIN, 
            Font.SIZE_SMALL
);  

            int position = 0;
            if(COLOR){
                g.setColor(255255255);       
            }else
                g.setColor(192192192);            
        g.fillRect(0, position, width, font1.getHeight());
      }
            if(COLOR){
                g.setColor(255255255);       
            }else{
                g.setColor(000);
      }
      g.setFont(font1);
            g.drawString("LARGE SIZE FONT"0, position, Graphics.LEFT | 
            Graphics.TOP
);

      position = position + font1.getHeight() 10;
            g.setFont(font2);
        g.drawString("MEDIUM SIZE FONT"0, position, Graphics.LEFT | 
        Graphics.TOP
);
            g.setColor(000);       
            position = position + font1.getHeight() 10;            
            g.setFont(font3);
            g.drawString("SMALL SIZE FONT"0, position, Graphics.LEFT | 
            Graphics.TOP
);
      position = position + font1.getHeight() 10;
      g.drawLine(0, font3.getHeight() + position - 1, width, font3.getHeight() 
      + position - 
1);
      painting = false;
    }
  }
}

Download Source Code

                         

[an error occurred while processing this directive]