Core Java| JSP| Servlets| XML| EJB| JEE5| Web Services| J2ME| Glossary| Questions?

 

 

 

 

 

 

 

 

 

 

 

 

 

Search Tutorials

Latest Questions
Comments
 
J2ME Display Size Example 
 

In the given J2ME Midlet example, we are going to display the size of the screen. Like a below given image 1, the midlet will print few items on the screen and the screen size will be displayed at the command prompt (image 2).

 

J2ME Display Size Example

                         

In the given J2ME Midlet example, we are going to display the size of the screen. Like a below given image 1, the midlet will print few items on the screen and the screen size will be displayed at the command prompt (image 2).

 

 

 

 

 

Image 1

Image 2

To get the size of the screen, we have used getwidth and getheight method in our example.

Source Code of DisplaySize.java

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

public class DisplaySize extends MIDlet{
  private Display display;

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

  public void pauseApp(){}

  public void destroyApp(boolean unconditional){}
}

class DisplaySizeCanvas extends Canvas {
    public void paint(Graphics g) {
        int width = getWidth();
        int height = getHeight();
    
        g.setColor(25500);
        g.fillRect(00, width, height);
        
        g.setColor(00255);
        g.drawString("Sandeep Kumar Suman"00
    Graphics.TOP | Graphics.LEFT
);
        
        Font font = g.getFont();
        g.drawString("Software Developer"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
);

    System.out.println("Height Of Display Screen: " + height);
    System.out.println("Width Of Display Screen: " + width);
    }
}

Download Source Code

                         

» View all related tutorials
Related Tags: c io vi lock this block set frame example ram exam locks e il manual blocks man in as m

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

Audio Version
Reload Image
 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Training Courses
Tell A Friend
Your Friend Name
Software Solutions
Least Viewed
Most Rated
Recently Viewed
Search Tutorials

 

 
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Indian Software Development Company | iPhone Development Company in India | Flex Development Company in India | Java Training Delhi | Java Training at Noida |

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2008. All rights reserved.