×

Discussion Board

Results 1 to 7 of 7
  1. #1
    Registered User
    Join Date
    Nov 2005
    Posts
    33

    drawString() is painting in BGImage

    hi folks,

    my sonyericcson emulator's width:176 and height:220.
    Im having one image with same height but double the width.

    so,
    g.drawImage(transparentImage,0,0,g.TOP|g.LEFT);

    will display only the first half of the img.

    when i press any key , i want to show the second hidden part of the same image so that it creates an illusion of moving.

    when i used,
    g.translate(-175,0);

    its suddenly moving to second part but not creates any illusion of movement.

    before painting transparentImage i ve already painted BGImage.

    now if i use

    g.translate(-175,0);
    g.drawString("painting",8,96,g.TOP|g.LEFT);

    the "painting " is painted in the BGImage and not on top of transparentImage.

    Please suggest....

    1. how to move the img gradually
    2. how to drawstring on top of that moved img


    Thanks in advance

    yafy

  2. #2
    Super Contributor
    Join Date
    Feb 2006
    Posts
    689

    Re: drawString() is painting in BGImage

    Hi,
    instead of hardcoding the values for drawing the image just use variables that increases or decreases their values as the key is pressed.

    thanks
    Soku

  3. #3
    Registered User
    Join Date
    Nov 2005
    Posts
    33

    Re: drawString() is painting in BGImage

    thanks for reply...

    i actually used the following code below,

    for(int i=0;i<-175;i--){
    g.translate(i,0);
    try{
    t.sleep(500);
    }catch(Exception e){}
    g.drawImage(interfaceImage,i,0,g.TOP|g.LEFT);

    }

    but its not working.Am i correct or how can i modify my code...
    plz suggest.

    yafy

  4. #4
    Super Contributor
    Join Date
    Mar 2006
    Posts
    516

    Re: drawString() is painting in BGImage

    Hi Yafy,

    I think here is a problem in ur code.
    where have u written the code.
    does it execute the painting part.ie: does it call the repaint() & serviceRepaints() in the for loop itself ?
    For every g.translate(i,0); u have to call repaint or servicerepaints()


    If possible Can u please post the whole sample code


    Wang

  5. #5
    Registered User
    Join Date
    Nov 2005
    Posts
    33

    Re: drawString() is painting in BGImage

    hi

    Quote: "For every g.translate(i,0); u have to call repaint or servicerepaints()"
    thats also not working.

    Below is my paint :


    public void paint(Graphics g)
    {

    System.out.println("enter into paint.....");

    int w = g.getClipWidth();
    int h = g.getClipHeight();

    // wordWrap = new WordWrap(Font.getFont( Font.FACE_PROPORTIONAL,
    // Font.STYLE_BOLD | Font.STYLE_PLAIN, Font.SIZE_SMALL ),QStr,w);

    g.setFont( Font.getFont( Font.FACE_PROPORTIONAL,
    Font.STYLE_BOLD | Font.STYLE_PLAIN, Font.SIZE_SMALL ) );


    g.setGrayScale(255);

    g.drawImage(BackgroundImage,0,0,g.TOP|g.LEFT);

    g.drawImage(questionBarImage,0,0,g.TOP|g.LEFT);
    g.setClip(0, 0, interfaceImage.getWidth(), interfaceImage.getHeight());

    if(translateFlag == 1 ){

    for(int i=0;i<-175;i--){
    g.translate(i,0);
    repaint();
    g.drawImage(interfaceImage,i,0,g.TOP|g.LEFT);
    try{
    t.sleep(500);
    }catch(Exception e){}

    }

    g.drawImage(okButtonImage,175,210,g.TOP|g.LEFT);
    g.drawImage(passButtonImage,315,210,g.TOP|g.LEFT);

    g.drawString(A1Str,215,86,g.TOP|g.LEFT);
    g.drawString(A2Str,215,120,g.TOP|g.LEFT);
    g.drawString(A3Str,215,154,g.TOP|g.LEFT);
    g.drawString(A4Str,215,188,g.TOP|g.LEFT);
    translateFlag = 0;
    }else {}
    if(playFlag == 1){
    playFlag = 0;
    switch(spinMidlet.randomCategory)
    {

    case 1:
    translateFlag = 1;

    g.drawImage(interfaceImage,0,0,g.TOP|g.LEFT);//first part of img is painted here correcty
    g.drawImage(generalImage,75,5,g.TOP|g.LEFT);
    //after painting generalimg i want to move the translateimg.

    repaint();break;
    case 2:

    ..........

    }
    }}
    else{
    g.drawImage(interfaceImage,0,0,g.TOP|g.LEFT);


    }
    g.drawImage(playButtonImage,10,210,g.TOP|g.LEFT);

    }//end paint


    ro be clear ,when i press play button (playFlag=1) generalimg is painted on interfaceimg and set translateflag =1 .after this only i want to translate(move) interfaceimg .

    thanks
    yafy

  6. #6
    Super Contributor
    Join Date
    Feb 2006
    Posts
    689

    Re: drawString() is painting in BGImage

    Hi Yafy,
    Please use the paint method only for painting.Please avoid the logic and other non-painting methods from the paint method.

    Thanks
    Soku

  7. #7
    Super Contributor
    Join Date
    Mar 2006
    Posts
    516

    Re: drawString() is painting in BGImage

    Hi yafy.

    http://www.microjava.com/developer/f...ontent_id=1835


    here is a sample wich helps u to scroll an image.

    Regards,
    Wang

Similar Threads

  1. Wrap text using drawString ?
    By artemg in forum Mobile Java General
    Replies: 6
    Last Post: 2009-06-25, 10:25
  2. Is pixel by pixel painting possible in standard MIDP?
    By MobileVisuals in forum Mobile Java Media (Graphics & Sounds)
    Replies: 0
    Last Post: 2006-01-02, 19:37
  3. More offscreen DrawString problems !!! (Series 60 J2ME SDK)
    By cbazza@poliplus.com in forum Mobile Java Media (Graphics & Sounds)
    Replies: 0
    Last Post: 2003-06-13, 21:00
  4. Display text on Canvas other than drawString
    By sengaste in forum Mobile Java General
    Replies: 1
    Last Post: 2003-04-15, 11:00
  5. bgcolor is not painting the entire screen
    By harikrishnag in forum Browsing and Mark-ups
    Replies: 1
    Last Post: 2002-10-21, 21:44

Posting Permissions

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