×

Discussion Board

Results 1 to 3 of 3
  1. #1
    Regular Contributor
    Join Date
    Nov 2007
    Posts
    254

    Adding Command to an Alert

    we can add Command to the alert
    and it goes out after some time plz have a look
    Can Any one give how to make it like AlertType FOREVER


    regards
    Arun Gupta

    /*
    * To change this template, choose Tools | Templates
    * and open the template in the editor.
    */

    package hello;

    import javax.microedition.lcdui.Alert;
    import javax.microedition.lcdui.AlertType;
    import javax.microedition.lcdui.Canvas;
    import javax.microedition.lcdui.Command;
    import javax.microedition.lcdui.CommandListener;
    import javax.microedition.lcdui.Display;
    import javax.microedition.lcdui.Displayable;
    import javax.microedition.lcdui.Graphics;
    import javax.microedition.midlet.MIDlet;

    /**
    *
    * @author Arun Gupta
    */
    class CanvasDisplayable extends Canvas implements CommandListener
    {
    public Alert alert;
    Command showalert,close;
    public boolean show = false;
    MIDlet mid;
    public CanvasDisplayable(MIDlet mid)
    {

    alert = new Alert("Alert","Arun",null,AlertType.CONFIRMATION);

    showalert = new Command("showalert",Command.SCREEN,1);

    close = new Command("Close",Command.SCREEN,1);

    alert.setCommandListener(this);

    this.addCommand(showalert);

    setCommandListener(this);

    this.mid = mid;
    }
    protected void paint(Graphics graphics)
    {
    graphics.drawRect(0, 0, this.getWidth(),this.getHeight());
    graphics.setColor(255);
    graphics.fillRect(0, 0, this.getWidth(),this.getHeight());
    graphics.drawString("Akdajd", UP, UP,Graphics.LEFT|Graphics.TOP);
    if(show == true)
    {
    show = false;
    if(close!=null)
    alert.addCommand(close);
    Display.getDisplay(mid).setCurrent(alert);
    }


    }

    public void commandAction(Command cmd, Displayable arg1) {
    System.out.println(cmd.getLabel());
    if(cmd.getLabel().equals("showalert"))
    {
    show = true;
    repaint();
    }
    else if (cmd.getLabel().equals("Close"))
    {
    Display.getDisplay(mid).setCurrent(this);
    }
    }

    }

  2. #2
    Super Contributor
    Join Date
    Apr 2007
    Posts
    2,708

    Re: Adding Command to an Alert

    alert.setTimeout(Alert.FOREVER);

  3. #3
    Super Contributor
    Join Date
    Sep 2008
    Location
    Noida, U.P.
    Posts
    1,330

    Thumbs up Re: Adding Command to an Alert

    Alert alert = new Alert("","msg",null,AlertType.WARNING);
    alert.setTimeout(Alert.FOREVER);
    alert.addCommand(cmd);
    alert.setCommandListener(CommandListener);
    display.setCurrent(alert);
    thanks,
    jitu_goldie..

    KEEP TRYING..

Similar Threads

  1. Change language for alert soft button in j2me
    By trandinhduy in forum Mobile Java General
    Replies: 2
    Last Post: 2009-05-04, 07:49
  2. Using images within an Alert
    By ayushv2005 in forum Mobile Java General
    Replies: 2
    Last Post: 2008-09-18, 09:01
  3. Alert confusion
    By Peanuts1971 in forum Mobile Java General
    Replies: 2
    Last Post: 2007-05-29, 04:40
  4. preverify error. PLZ HELP
    By michaelhann89 in forum Mobile Java Tools & SDKs
    Replies: 14
    Last Post: 2007-03-22, 22:51
  5. Replies: 1
    Last Post: 2003-03-17, 02:07

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×