×

Discussion Board

Results 1 to 7 of 7
  1. #1
    Registered User
    Join Date
    Apr 2008
    Posts
    9

    how to print some text in emulator

    Hi

    can any one pls tell me how i can print some text on the emulator.

    I added the statement "System.out.println("Hello World"); " in "startApp()". but it is not printing anything. its just showing a blank background with the project name on it.

    pls tell me...

    Regards,
    Naveen.

  2. #2
    Registered User
    Join Date
    Apr 2008
    Posts
    3

    Re: how to print some text in emulator

    using System.out.println() , you will print the text on the console , not on the emulator.
    use a Graphics object g.
    g.drawString(string,x,y,anchor point);

  3. #3
    Registered User
    Join Date
    Apr 2008
    Posts
    9

    Re: how to print some text in emulator

    Hi vishal,

    What is this anchor point..??
    can you give me an example for g.drawString(string,x,y,anchor point);

  4. #4
    Registered User
    Join Date
    Apr 2008
    Posts
    3

    Re: how to print some text in emulator

    g.drawString("Hello World",x,y,Graphics.TOP|Graphics.LEFT);
    x & y are the int values

  5. #5
    Nokia Developer Champion
    Join Date
    Nov 2007
    Location
    Rome, Italy
    Posts
    2,406

    Re: how to print some text in emulator

    Maybe this introductory article on J2me low level graphics could be of some help:

    http://today.java.net/pub/a/today/20...UI.html?page=4

    Pit

  6. #6
    Registered User
    Join Date
    Apr 2008
    Posts
    9

    Re: how to print some text in emulator

    What is wrong in this code... pls help me.
    this should print "hello world" on the screen.



    import javax.microedition.lcdui.Alert;
    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;
    import javax.microedition.midlet.MIDletStateChangeException;

    public class myMidlet extends MIDlet implements CommandListener{

    Alert alert;
    Command comExit;

    protected void destroyApp(boolean arg0) throws MIDletStateChangeException {
    // TODO Auto-generated method stub

    }

    protected void pauseApp() {
    // TODO Auto-generated method stub

    }

    protected void startApp() throws MIDletStateChangeException {
    // TODO Auto-generated method stub
    //System.out.println("Hello World");
    /*Graphics g = null;
    g.drawString("welcome to the Matrix",10,10,g.BOTTOM|g.RIGHT);*/
    alert = new Alert("Hello World");
    Display.getDisplay(this).setCurrent(alert);
    comExit = new Command("Exit", Command.EXIT, 1);
    alert.addCommand(comExit);
    alert.setCommandListener(this);
    }

    public void commandAction(Command cmd, Displayable arg1) {
    // TODO Auto-generated method stub
    if (cmd == comExit) {
    exit();
    }
    }

    public void exit() {
    notifyDestroyed();
    }


    }

  7. #7
    Nokia Developer Champion
    Join Date
    Nov 2007
    Location
    Rome, Italy
    Posts
    2,406

    Re: how to print some text in emulator

    First, you should define a Displayable object and set it as current Display for your MIDlet, with the Display setCurrent() method.

    Secondly, you should perform low level graphics paint operations within Canvas paint() method, whose argument is the Graphics instance you're trying to use in your code.

    For example you can extend Canvas this way:
    Code:
    public class MyCanvas extends Canvas
    {
    	protected void paint(Graphics g)
    	{
    		g.drawString("welcome to the Matrix", 10, 10, Graphics.BOTTOM | Graphics.RIGHT);
    	}
    }
    And then, in your MIDlet startApp() method, you can do:
    Code:
    Display.getDisplay(this).setCurrent(new MyCanvas());
    Hope it helps
    Pit

Similar Threads

  1. Exit form from edit mode
    By tqchcm in forum Symbian User Interface
    Replies: 13
    Last Post: 2007-10-31, 06:06
  2. Print text independent of printer drivers
    By blackspear in forum Bluetooth Technology
    Replies: 1
    Last Post: 2007-09-20, 07:58
  3. How to send an image with attachment in email
    By krtrivdi in forum Symbian
    Replies: 1
    Last Post: 2007-01-09, 12:07
  4. Replies: 8
    Last Post: 2005-08-09, 14:56
  5. Unable to open a text document on emulator.
    By yuva69 in forum Symbian
    Replies: 0
    Last Post: 2002-06-24, 12:45

Posting Permissions

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