Home J2me Text MIDlet Example



Text MIDlet Example
Posted on: December 19, 2008 at 12:00 AM
With the help of text midlet example, we are going to show text using canvas class at different locations on the screen. Given are the methods, that are used in the example...

Text MIDlet Example

     

With the help of text midlet example, we are going to show text using canvas class at different locations on the screen. Given are the methods, that are used in the example... 

  • int width = getWidth();   
  • int height = getHeight();  
  • g.setColor(255, 162, 117);   
  • g.fillRect(0, 0, width, height);   
  • g.setColor(0, 0, 255);   
  • g.drawString("Sandeep Kumar Suman", 0, 0, Graphics.TOP | Graphics.LEFT);  
  • Font font = g.getFont();   
  • g.drawString("Master of Computer Application(2008)", 0, font.getHeight(), Graphics.TOP | Graphics.LEFT);  
  • g.drawString("Mobile No: +919313985248", width, height, Graphics.BOTTOM | Graphics.RIGHT);  
  • String str = "Roseindia Tech. Pvt. Ltd.";     
  • font = Font.getFont(Font.FACE_PROPORTIONAL, Font.STYLE_UNDERLINED, Font.SIZE_LARGE);   
  • g.setFont(font);   
  • g.drawString(str, 0, height/2, Graphics.LEFT | Graphics.BASELINE);  
  • int x = font.stringWidth(str);   
  • g.setColor(0, 0, 255);   
  • g.setFont(Font.getFont(Font.FACE_PROPORTIONAL, Font.STYLE_BOLD | Font.STYLE_ITALIC, Font.SIZE_MEDIUM));
  • g.drawString(" Delhi, India", x, height/2, Graphics.LEFT | Graphics.BASELINE);

The Application is as follows:

 

Source Code of TextExample.java

import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;

public class TextExample extends MIDlet{
  private Display display;

  public void startApp(){
  Canvas canvas = new TextCanvas();
  display = Display.getDisplay(this);
  display.setCurrent(canvas);
  }

  public void pauseApp(){}

  public void destroyApp(boolean unconditional){}
}

class TextCanvas extends Canvas {
  public void paint(Graphics g) {
  int width = getWidth();
  int height = getHeight();

  g.setColor(255162117);
  g.fillRect(00, width, height);
  
  g.setColor(00255);
  g.drawString("Sandeep Kumar Suman"00, Graphics.TOP | 
  Graphics.LEFT);

  
  Font font = g.getFont();
  g.drawString("Master of Computer Application(2008)"0
  font.getHeight(), Graphics.TOP | Graphics.LEFT);

  
  g.drawString("Mobile No: +919313985248", width, height, 
  Graphics.BOTTOM | Graphics.RIGHT);
  
  String str = "Roseindia Tech. Pvt. Ltd.";  
  font = Font.getFont(Font.FACE_PROPORTIONAL, 
  Font.STYLE_UNDERLINED, Font.SIZE_LARGE);

  g.setFont(font);
  g.drawString(str, 0, height/2, Graphics.LEFT | Graphics.BASELINE);
 
  int x = font.stringWidth(str);
  g.setColor(00255);
  g.setFont(Font.getFont(Font.FACE_PROPORTIONAL, Font.STYLE_BOLD | 
  Font.STYLE_ITALIC, Font.SIZE_MEDIUM));

  g.drawString(" Delhi, India", x, height/2, Graphics.LEFT | 
  Graphics.BASELINE);

  }
}

Download Source Code

Related Tags for Text MIDlet Example:
cclasstextdiffiomethodshelpcanvasmethodsedscreenusingidlocationshowiftexexamplewithtoidlmidletexamidleshexteitcanmidluseindifferentasmntcaletcllocmehowcatxaxampseeathaivmplgoarxtvascrssrenthshoatihatfepleplmiodsono


More Tutorials from this section

Ask Questions?    Discuss: Text MIDlet Example   View All Comments

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.