3 Replies Latest reply: Nov 19, 2010 11:51 PM by DarrylBurke RSS

    Help with a Class

    PinHead
      Hi can anyone help

      I've created a midlet and two classes the problem is that im trying to display the two classe in the midlet,I can get one class to display but not the other? Any help would be appreciated
      import javax.microedition.midlet.*;
      import javax.microedition.lcdui.*;
      
      /**
       * @author Administrator
       */
      public class ImageMidlet extends MIDlet
      {
          private Form mForm;   
          private ColorBackground col;
      
          public void startApp() 
          {
              Display display = Display.getDisplay( this );
              
              if( mForm == null )
              {
      
                  this.mForm = new Form( "Interface" );
                  
                  try
                  {
                      CustomImage cus = new CustomImage( "Button_Play_Pink1 copy.png");
      
                      this.mForm.append( cus );
                     
                  }
                  catch( Exception e )
                  {
                      this.mForm.append("Couldn't create Image");
                  }
              }
      
              ColorBackground col = new ColorBackground( this );
              display.setCurrent( this.col );
              display.setCurrent( this.mForm );
          }
      
          public void pauseApp()
          {
          }
      
          public void destroyApp(boolean unconditional)
          {
          }
      }
        • 1. Re: Help with a Class
          DarrylBurke
          Pin Head wrote:
          public class ImageMidlet extends MIDlet
          {
          :
          :
          private Form mForm;   
          private ColorBackground col; // <-----
          
          public void startApp() 
          {
          :
          :
          ColorBackground col = new ColorBackground( this ); // <-----
          display.setCurrent( this.col ); //this.col is null
          :
          :
          }
          You have two variables named <tt>col</tt>, the one an instance field which is never iniitialized so is null and the other a local variable which is initialized but never accessed.

          db
          • 2. Re: Help with a Class
            PinHead
            Hi,
            I changed my code to this all I get is my class customItem show ,on the emulator but no background class
            help would be appreciated.
            import javax.microedition.midlet.*;
            import javax.microedition.lcdui.*;
            
            /**
             * @author Administrator
             */
            public class ImageMidlet extends MIDlet
            {
                private Form mForm;   
                
               public void startApp() 
                {
                    Display display = Display.getDisplay( this );        
                    if( mForm == null )
                    {
                        this.mForm = new Form( "Interface" );
                        try
                        {
                            CustomImage cus = new CustomImage( "Button_Play_Pink1 copy.png" );
                            this.mForm.append( cus );
                        }
                        catch( Exception e )
                        {
                            this.mForm.append("Couldn't create Image");
                        }
                    }
                    display.setCurrent( new ColorBackground( this ));
                    display.setCurrent( this.mForm );
                }
            • 3. Re: Help with a Class
              DarrylBurke
              Pin Head wrote:
              display.setCurrent( new ColorBackground( this ));
              display.setCurrent( this.mForm );
              }
              What do you think those two consecutive <tt>setCurrent(...)</tt> calls do? Read the API for <tt>Display</tt>.
              Requests that a different Displayable object be made visible on the display.
              :
              For example, if screen S1 is current, then
              d.setCurrent(S2);
              d.setCurrent(S3);
              may eventually result in S3 being made current, bypassing S2 entirely.

              db