Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Contributor
Posts: 32
Registered: ‎09-06-2010
My Device: Not Specified

Custom Class does not display.

[ Edited ]

I have made a program, that works in j2me I have also managed to translate it into android. I was wondering why when I eventually manage to make some code. My class does not display at all, No custom class information gets displayed. My interface is intricate. I had a similar problem with android but I managed to get round it.

The form title is displayed and most of the rest of the program seems to work. But the custom class image does not display no information is drawn no strings. The arc and circles are not displayed.

 

the paint method.

Remember this works in j2me and android, so I feel there is something that is done fundamentally different in BB.

 

   protected void paint(Graphics g)
    {
     
                        int bottomboundaryofpreviousitem = 0;
            int basiclineheight = 0;
            int y = anchoryposition;

        do
        {

            //screen refresh wipe
            g.setColor(255, 255, 255);
            g.fillRect(0, 0, getPrefContentWidth(d), getPrefContentHeight(d));

            g.setColor(130, 200, 50);
            g.drawRect(spacearoundedges,spacearoundedges, getMinContentWidth() , getMinContentHeight());


            if (frm.backgroundimg != null)
            {
                g.drawImage(frm.backgroundimg, getMinContentWidth() / 2, 2, Graphics.TOP | Graphics.LEFT);
            }
            firstt++;
            if (vec == null || vec.size() == 0)
            {
                return;
            }
            g.setColor(0, 0, 0);
         
            bottomboundaryofpreviousitem = 0;
            basiclineheight = 0;
            y = anchoryposition;
            g.setStrokeStyle(Graphics.SOLID);

            short vecsize = (short) vec.size();
            if(vectorfortouchscreen.size()!=vecsize)
            {
                vectorfortouchscreen.setSize(vecsize);
            }
            for (short theitemposition = 0; theitemposition < vecsize; theitemposition++)
            {
                y = y + basiclineheight +spacebetweenchoices;
                bottomboundaryofpreviousitem = y;

      
                    y = drawItem(g, vec.elementAt(theitemposition), spacearoundt2+spc, y);
                    printitemheight = (y - bottomboundaryofpreviousitem) + lineheight+spacebetweenchoices;
                    g.setColor(0, 0, 0);
                 
                    Integer position = new Integer(y);
                    vectorfortouchscreen.setElementAt(position,theitemposition);


                if (currentselection == theitemposition)
                {
                    selectionpositiontop = bottomboundaryofpreviousitem;
                    currentgap = printitemheight;
                }
                if (currentselection == (theitemposition - 1))//below visually
                {
                    heightofitembelow = printitemheight;
                }

                if (currentselection == (theitemposition + 1))//above visually
                {
           

                    heightofitemabove = printitemheight;
                    g.setColor(255, 255, 255);
                }
     
              
              
                basiclineheight = lineheight;
                    if(y+f.getHeight()>spacearoundedges+getMinContentHeight())                //check that the bottom boundary is in view, if not then stop
                //greatestyvalue is the size of the the whole screen not the viewport
                    {
                    lowestiteminviewwindow = theitemposition ;
                    lowestitemyoutviewwindow = y-printitemheight;
                           setSelectionStuff(g);
                        vectorfortouchscreen.setSize(theitemposition+1);
                        return;
                    }
                    if(y<spacearoundedges)
                    {

                        highestiteminviewwindow = theitemposition;
                        highestitemyoutviewwindow = lowestitemyoutviewwindow-printitemheight;

                    }
             
            }

            setSelectionStuff(g);

        } while (jj != 4);
 
    }

the method that helps paint.

public int drawItem(Graphics g, Object element, int lowestxvaluepossible, int y)
    {
        String bp = "";
        if(cosmetics!=null) bp= (String) cosmetics.screenVal(element);//
        else
        {
            bp =  ((MyDisp) element).toDisp(cosmetics);
        }
        StringBuffer stbuff = ReUsableClasses.stbuff;
        stbuff.delete(0, stbuff.length());
        stbuff.append(bp);
        if(stbuff.charAt(stbuff.length()-1)!=' ') stbuff.append('.');
        else stbuff.setCharAt(stbuff.length()-1, '.');

        int thelength = stbuff.length();
        char[] rls = new char[thelength];
        stbuff.getChars(0, thelength, rls, status);

        rls[0]=Character.toUpperCase(rls[0]);
        --thelength;
        short poss = -1;
        int wordlength = 0;
        int startcharpos = 0;
        startx = lowestxvaluepossible;
        char c;
        if (dataselector)
        {
            if(inSight(y)) g.drawArc(lowestxvaluepossible-arcwidthnheight-arcxhelp, y, 13, 13, 0, 360);
        }
        while (poss < thelength)
        {

            c = rls[++poss];
            switch(c)
            {
                 
                case ' ':

                    wordlength = f.charsWidth(rls, startcharpos, (poss + 1 - startcharpos));
             

                    y = passEndAndMove(lowestxvaluepossible, y, wordlength);

                    if(inSight(y)) g.drawChars(rls, startcharpos, (poss - startcharpos), startx, y, Graphics.TOP | Graphics.LEFT);

                    startcharpos = poss + 1;
                    startx = endd;
                    break;
                case '\u00fe':
                    y += lineheight;
                    startx=lowestxvaluepossible;
                       startcharpos = poss + 1;


                default:

            }

        }
   
 
        wordlength = f.charsWidth(rls, startcharpos, (poss + 1 - startcharpos));

        y = passEndAndMove(lowestxvaluepossible, y, wordlength);


        while (startcharpos < rls.length)
        {
            wordlength = f.charWidth(rls[startcharpos]);
            y = passEndAndMove(lowestxvaluepossible, y, wordlength);
            if(inSight(y)) g.drawChar(rls[startcharpos], startx, y, Graphics.TOP | Graphics.LEFT);
            startcharpos++;
            startx = endd;
        }
 

        return y;


    }
second method that helps.
 private void setSelectionStuff(Graphics g)
       {
    
        g.setColor(145, 169, 63);
        g.setStrokeStyle(Graphics.SOLID);
      
        if (dataselector) {
            g.setColor(0, 0, 0);
            g.fillArc(selectionarcxposition, selectionpositiontop + 2, 9, 9, 0, 360);
            g.setColor(193, 159, 64);
        }
        if (_inTraversal) {
            g.fillRoundRect(froundposx, selectionpositiontop - 1, getMinContentWidth() - 25, currentgap, 8, 10);
        }
        g.setColor(22, 86, 96);
        drawItem(g, vec.elementAt(currentselection), spacearoundt2 + spc, selectionpositiontop);
    }



    protected int getMinContentHeight()
    {
        return getPrefContentHeight(0)-spacearoundt2;
    }

    protected int getMinContentWidth()
    {
        return getPrefContentWidth(0) - spacearoundt2;
    }

    protected int getPrefContentHeight(int width)
    {

        return frm.getHeight()-spacearoundedges;
 
    }

    protected int getPrefContentWidth(int height)
    {
 
        return availablewidth - spacearoundedges;
    }


Screen.getWidth() this is used when the class is created to set the availablewidth.
frm.getHeight() is used dynamically from a class that extends import javax.microedition.lcdui.Form
Developer
Posts: 1,305
Registered: ‎01-21-2009
My Device: Not Specified

Re: Custom Class does not display.

Does it run and display a blank screen? Or just not run at all? Are you just running it as a MIDlet or did you do some porting to BB?




Solved? click "Accept as solution". Helpful? give kudos by clicking on the star.
Contributor
Posts: 32
Registered: ‎09-06-2010
My Device: Not Specified

Re: Custom Class does not display.

No porting is done I just run through the cod conversion. I wrote the program in netbeans and eclipse.

Contributor
Posts: 32
Registered: ‎09-06-2010
My Device: Not Specified

Re: Custom Class does not display.

What are the porting issues associated with customitem

Developer
Posts: 1,305
Registered: ‎01-21-2009
My Device: Not Specified

Re: Custom Class does not display.

[ Edited ]

You need to restrict your code to use only the JSRs supported by RIM. (In particular, JSR 296 - AWT/Swing - is not supported.) I'm not aware of any other issues that would prevent a MIDlet from running.




Solved? click "Accept as solution". Helpful? give kudos by clicking on the star.
Contributor
Posts: 32
Registered: ‎09-06-2010
My Device: Not Specified

Re: Custom Class does not display.

The midlet runs, it is just the custom class, is just a white screen on the emulator. the form headings are there.

Developer
Posts: 1,305
Registered: ‎01-21-2009
My Device: Not Specified

Re: Custom Class does not display.

Maybe if you posted some code for the custom item, someone here could diagnose what's wrong.




Solved? click "Accept as solution". Helpful? give kudos by clicking on the star.
Contributor
Posts: 32
Registered: ‎09-06-2010
My Device: Not Specified

Re: Custom Class does not display.

[ Edited ]

the paint method.

Remember this works in j2me and android, so I feel there is something that is done fundamentally different in BB.

 

   protected void paint(Graphics g)
    {
     
                        int bottomboundaryofpreviousitem = 0;
            int basiclineheight = 0;
            int y = anchoryposition;

        do
        {

            //screen refresh wipe
            g.setColor(255, 255, 255);
            g.fillRect(0, 0, getPrefContentWidth(d), getPrefContentHeight(d));

            g.setColor(130, 200, 50);
            g.drawRect(spacearoundedges,spacearoundedges, getMinContentWidth() , getMinContentHeight());


            if (frm.backgroundimg != null)
            {
                g.drawImage(frm.backgroundimg, getMinContentWidth() / 2, 2, Graphics.TOP | Graphics.LEFT);
            }
            firstt++;
            if (vec == null || vec.size() == 0)
            {
                return;
            }
            g.setColor(0, 0, 0);
         
            bottomboundaryofpreviousitem = 0;
            basiclineheight = 0;
            y = anchoryposition;
            g.setStrokeStyle(Graphics.SOLID);

            short vecsize = (short) vec.size();
            if(vectorfortouchscreen.size()!=vecsize)
            {
                vectorfortouchscreen.setSize(vecsize);
            }
            for (short theitemposition = 0; theitemposition < vecsize; theitemposition++)
            {
                y = y + basiclineheight +spacebetweenchoices;
                bottomboundaryofpreviousitem = y;

      
                    y = drawItem(g, vec.elementAt(theitemposition), spacearoundt2+spc, y);
                    printitemheight = (y - bottomboundaryofpreviousitem) + lineheight+spacebetweenchoices;
                    g.setColor(0, 0, 0);
                 
                    Integer position = new Integer(y);
                    vectorfortouchscreen.setElementAt(position,theitemposition);


                if (currentselection == theitemposition)
                {
                    selectionpositiontop = bottomboundaryofpreviousitem;
                    currentgap = printitemheight;
                }
                if (currentselection == (theitemposition - 1))//below visually
                {
                    heightofitembelow = printitemheight;
                }

                if (currentselection == (theitemposition + 1))//above visually
                {
           

                    heightofitemabove = printitemheight;
                    g.setColor(255, 255, 255);
                }
     
              
              
                basiclineheight = lineheight;
                    if(y+f.getHeight()>spacearoundedges+getMinContentHeight())                //check that the bottom boundary is in view, if not then stop
                //greatestyvalue is the size of the the whole screen not the viewport
                    {
                    lowestiteminviewwindow = theitemposition ;
                    lowestitemyoutviewwindow = y-printitemheight;
                           setSelectionStuff(g);
                        vectorfortouchscreen.setSize(theitemposition+1);
                        return;
                    }
                    if(y<spacearoundedges)
                    {

                        highestiteminviewwindow = theitemposition;
                        highestitemyoutviewwindow = lowestitemyoutviewwindow-printitemheight;

                    }
             
            }

            setSelectionStuff(g);

        } while (jj != 4);
 
    }

the method that helps paint.

public int drawItem(Graphics g, Object element, int lowestxvaluepossible, int y)
    {
        String bp = "";
        if(cosmetics!=null) bp= (String) cosmetics.screenVal(element);//
        else
        {
            bp =  ((MyDisp) element).toDisp(cosmetics);
        }
        StringBuffer stbuff = ReUsableClasses.stbuff;
        stbuff.delete(0, stbuff.length());
        stbuff.append(bp);
        if(stbuff.charAt(stbuff.length()-1)!=' ') stbuff.append('.');
        else stbuff.setCharAt(stbuff.length()-1, '.');

        int thelength = stbuff.length();
        char[] rls = new char[thelength];
        stbuff.getChars(0, thelength, rls, status);

        rls[0]=Character.toUpperCase(rls[0]);
        --thelength;
        short poss = -1;
        int wordlength = 0;
        int startcharpos = 0;
        startx = lowestxvaluepossible;
        char c;
        if (dataselector)
        {
            if(inSight(y)) g.drawArc(lowestxvaluepossible-arcwidthnheight-arcxhelp, y, 13, 13, 0, 360);
        }
        while (poss < thelength)
        {

            c = rls[++poss];
            switch(c)
            {
                 
                case ' ':

                    wordlength = f.charsWidth(rls, startcharpos, (poss + 1 - startcharpos));
             

                    y = passEndAndMove(lowestxvaluepossible, y, wordlength);

                    if(inSight(y)) g.drawChars(rls, startcharpos, (poss - startcharpos), startx, y, Graphics.TOP | Graphics.LEFT);

                    startcharpos = poss + 1;
                    startx = endd;
                    break;
                case '\u00fe':
                    y += lineheight;
                    startx=lowestxvaluepossible;
                       startcharpos = poss + 1;


                default:

            }

        }
   
 
        wordlength = f.charsWidth(rls, startcharpos, (poss + 1 - startcharpos));

        y = passEndAndMove(lowestxvaluepossible, y, wordlength);


        while (startcharpos < rls.length)
        {
            wordlength = f.charWidth(rls[startcharpos]);
            y = passEndAndMove(lowestxvaluepossible, y, wordlength);
            if(inSight(y)) g.drawChar(rls[startcharpos], startx, y, Graphics.TOP | Graphics.LEFT);
            startcharpos++;
            startx = endd;
        }
 

        return y;


    }
second method that helps.
 private void setSelectionStuff(Graphics g)
       {
    
        g.setColor(145, 169, 63);
        g.setStrokeStyle(Graphics.SOLID);
      
        if (dataselector) {
            g.setColor(0, 0, 0);
            g.fillArc(selectionarcxposition, selectionpositiontop + 2, 9, 9, 0, 360);
            g.setColor(193, 159, 64);
        }
        if (_inTraversal) {
            g.fillRoundRect(froundposx, selectionpositiontop - 1, getMinContentWidth() - 25, currentgap, 8, 10);
        }
        g.setColor(22, 86, 96);
        drawItem(g, vec.elementAt(currentselection), spacearoundt2 + spc, selectionpositiontop);
    }



    protected int getMinContentHeight()
    {
        return getPrefContentHeight(0)-spacearoundt2;
    }

    protected int getMinContentWidth()
    {
        return getPrefContentWidth(0) - spacearoundt2;
    }

    protected int getPrefContentHeight(int width)
    {

        return frm.getHeight()-spacearoundedges;
 
    }

    protected int getPrefContentWidth(int height)
    {
 
        return availablewidth - spacearoundedges;
    }


Screen.getWidth() this is used when the class is created to set the availablewidth.
frm.getHeight() is used dynamically from a class that extends import javax.microedition.lcdui.Form
Highlighted
Developer
Posts: 1,305
Registered: ‎01-21-2009
My Device: Not Specified

Re: Custom Class does not display.

Have you tried stepping through the code to verify that paint() is indeed being called and to see what values are being used in the drawing methods? It would be good to verify that the problem is somewhere in the drawing code itself.

 

One technique for diagnosing this is to temporarily replace your paint method body with something very simple - say, draw a line across the center of the screen. If that doesn't work, then the problem is somewhere outside the drawing code itself. If it does work, then incrementally add in what you really want until you find the problem.




Solved? click "Accept as solution". Helpful? give kudos by clicking on the star.