×

Discussion Board

Results 1 to 6 of 6
  1. #1
    Registered User
    Join Date
    Feb 2009
    Posts
    13

    How can i use a ticker while using canvas

    Hi all,

    In my J2em application, I am using canvas class. To draw a string i am using g.drawstring function.
    Now i want to use ticker for that string because my string is going out of mobile screen.
    Can anyone tell me the solution for this? In the high level programming i know how to use ticker but i've no idea how to use it in low level programming.plz help.

  2. #2
    Nokia Developer Champion
    Join Date
    Sep 2007
    Posts
    915

    Re: How can i use a ticker while using canvas

    Quote Originally Posted by mindIt View Post
    Hi all,

    In my J2em application, I am using canvas class. To draw a string i am using g.drawstring function.
    Now i want to use ticker for that string because my string is going out of mobile screen.
    Can anyone tell me the solution for this? In the high level programming i know how to use ticker but i've no idea how to use it in low level programming.plz help.
    I do not think that there will be direct way to put ticker in canvas but you can do in by calling repaint() for particular region of canvas and then update the content there but it will be some what tough. The another solution can be you should check screen's width and if that is more then the character's limit then you will have to look for it.

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

    Thumbs up Re: How can i use a ticker while using canvas

    Hi,

    public void run() {
    while (is_myThread_running) {
    repaint();
    try {
    Thread.sleep(30);
    } catch (Exception e) {
    Alert alert = new Alert("", "" + e.toString(), null, AlertType.ERROR);
    alert.setTimeout(Alert.FOREVER);
    xmlMid.dis.setCurrent(alert);
    }
    }
    }

    public void startThread() {
    myThread.start();
    }

    public void stopThread() {
    myThread = null;
    }



    int xOffset_SCROLL = 0;
    int yOffset_SCROLL = 0;

    public void scrollString(Graphics g, String resultString) {
    g.drawString(resultString, xOffset_SCROLL, yOffset_SCROLL, 0);
    xOffset_SCROLL--;
    if (xOffset_SCROLL < -(f1.stringWidth(resultString))) {
    xOffset_SCROLL = getWidth();
    }
    }


    void paint(Graphics g)
    {
    if (Font.getDefaultFont().stringWidth(Message) > 180) {
    yOffset_SCROLL = getHeight() / 5;
    scrollString(g, Message);
    } else {
    g.drawString(Message, 5, getHeight() / 5, 0);
    }

    }

    try this and reply pls. This is the code to move the text horizontally like ticker.

    thanks,
    jitu_goldie..
    thanks,
    jitu_goldie..

    KEEP TRYING..

  4. #4
    Regular Contributor
    Join Date
    Jun 2008
    Posts
    104

    Re: How can i use a ticker while using canvas

    Hi,
    By using repaint() u can do it easily.Just draw string on canvas and with help of a variable , decrease the starting string width and repaint it. try to do it and plz let me know .




    Thanks
    shravan

  5. #5
    Regular Contributor
    Join Date
    Jul 2008
    Posts
    148

    Re: How can i use a ticker while using canvas

    Hi,

    This code works for u.Try it and let me knw.

    public class TextExample1 extends Canvas implements Runnable
    {
    Thread thread;
    int x,y;
    String string = "Please wait....";
    textRoll midlet;
    int len ;

    public TextExample1(textRoll mid)
    {
    midlet = mid;
    setFullScreenMode(true);
    thread = new Thread(this);
    thread.start();
    x=getWidth()/2;
    y=getHeight()/2;
    len= string.length()*4;
    }

    protected void paint(Graphics g)
    {
    g.setColor(121,174,253);
    g.fillRect(0, 0, getWidth(), getHeight());
    g.setColor(0,0,0);
    g.drawRect(0,40,240,40);
    g.setColor(255,255,255);
    g.setFont(Font.getFont(Font.FACE_PROPORTIONAL,Font.STYLE_BOLD,Font.SIZE_MEDIUM));
    g.drawString(string,x,65,g.HCENTER | g.BASELINE);
    }
    public void run()
    {
    while(true)
    {
    if(x!=(0-len))
    {
    x--;
    }
    else
    x=240;
    try
    {
    thread.sleep(25);
    }
    catch (InterruptedException e)
    {
    e.printStackTrace();
    }
    repaint();
    }
    }
    }



    Tks,

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

    Re: How can i use a ticker while using canvas

    just change some definite values (like x =240) to something more adaptable (like x = getWidth()), otherwise this ticker will only look good on devices with a screen width of 240 pixels....

Similar Threads

  1. Problem with setFullScreenMode(true) in canvas
    By mramin05 in forum Mobile Java Media (Graphics & Sounds)
    Replies: 6
    Last Post: 2008-12-06, 05:45
  2. ticker class in canvas
    By maneeshv6 in forum Mobile Java General
    Replies: 0
    Last Post: 2008-01-21, 10:08
  3. How to create a partly transparent Canvas to lay on top of another Canvas?
    By mkleijer in forum Mobile Java Media (Graphics & Sounds)
    Replies: 4
    Last Post: 2007-05-22, 07:00
  4. Major problem with delegation to Canvas
    By bartekn in forum Mobile Java Media (Graphics & Sounds)
    Replies: 8
    Last Post: 2003-10-08, 17:46
  5. 7650 and 3650 Canvas and FullCanvas memory
    By marcilgen in forum Mobile Java General
    Replies: 5
    Last Post: 2003-07-08, 12:24

Posting Permissions

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