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

 

 

 

 

 

 

 

 

 

 

 

 

 

Search Tutorials

Latest Questions
Comments
 
User Define Alert Example 
 

Creating a user defined alert message, In the given example we have created a image that can be fill with some colors and text.

 

User Define Alert Example

                         

Creating a user defined alert message, In the given example we have created a image that can be fill with some colors and text. The following source code shows how to create the image, how to set the color and how to draw string. On clicking Alert option, a alert message will be displayed with image on the same screen.

 

 

 

 

 

im = Image.createImage(240220);
Graphics graphics = im.getGraphics();
Font font = Font.getFont(Font.FACE_SYSTEM, 
Font.STYLE_PLAIN, Font.SIZE_MEDIUM);

graphics.setFont(font);
graphics.setColor(196248192);
graphics.fillRoundRect(0,0, im.getWidth()-1
im.getHeight()-
12020); 
graphics.setColor(000);           
graphics.drawString(message, (im.getWidth()/2
- (font.stringWidth(message)/
2),
0, Graphics.TOP | Graphics.LEFT);

 

The Application is as follows:

 

 

 

Source Code of AlertExample.java

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

public class AlertExample extends MIDlet{
  private Display  display; 
  private ImageCanvas canvas;
  
  public AlertExample(){
    display = Display.getDisplay(this);
    canvas  = new ImageCanvas(this);
  }

  protected void startApp(){
    display.setCurrentcanvas );
  }

  protected void pauseApp(){ }

  protected void destroyApp(boolean unconditional){ }

  public void exitMIDlet(){
    destroyApp(true);
    notifyDestroyed();
  }
}

class ImageCanvas extends Canvas implements CommandListener{
  private Command cmExit;  
  private AlertExample midlet;
  private Image im = null;
  private String message = "This is alert message";
  
  public ImageCanvas(AlertExample midlet){
    this.midlet = midlet;

    cmExit = new Command("Exit", Command.EXIT, 1);
    addCommand(cmExit);
    setCommandListener(this);

    try{
      im = Image.createImage(240220);
      Graphics graphics = im.getGraphics();
      Font font = Font.getFont(Font.FACE_SYSTEM, Font.STYLE_PLAIN, Font.SIZE_MEDIUM);
      graphics.setFont(font);
      graphics.setColor(196248192);
      graphics.fillRoundRect(0,0, im.getWidth()-1, im.getHeight()-12020)
      graphics.setColor(000);           
      graphics.drawString(message, (im.getWidth()/2(font.stringWidth(message)/2),
       
0, Graphics.TOP | Graphics.LEFT);
    }
    catch (Exception e){
      System.err.println("Error during image creation");
    }    
  
  
  protected void paint(Graphics g){
    if (im != null)
      g.drawImage(im, getWidth()/2, getHeight()/2, Graphics.VCENTER | Graphics.HCENTER);
  }

  public void commandAction(Command c, Displayable d){
    if (c == cmExit)
      midlet.exitMIDlet();
  }
}

 

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.