Home J2me Different Size of Font MIDlet Example
Questions:Ask|Latest

 
 

Share on Google+Share on Google+

Different Size of Font MIDlet Example

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

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 unconditional) throws 
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(255, 128, 0);  
  g.fillRect(0, 0, 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(255, 255, 255); 
  }else{ 
  g.setColor(192, 192, 192);  
  g.fillRect(0, position, width, font1.getHeight());
  }
  if(COLOR){
  g.setColor(255, 255, 255); 
  }else{
  g.setColor(0, 0, 0);
  }
  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(0, 0, 0); 
  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

Advertisements

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: November 5, 2008

Related Tutorials

Ask Questions?    Discuss: Different Size of Font MIDlet Example  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments
DMCA.com