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
SirSaula
Posts: 30
Registered: ‎04-13-2010
My Device: N/A
My Carrier: T-Mobile

Painting the WHOLE background

My code fails to paint the whole background red for some reason it only does a line of red paint ...Please how do I paint the whole background.

 

 

I already use the function below but it does not paint the whole thing:

 

    public void paint(Graphics gs) {

gs.setBackgroundColor(0x00FF0000); // red background

gs.clear();

super.paint(gs);

}

 

 

 

Here is the code:

 

import net.rim.device.api.io.LineReader;
import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.component.*;
import net.rim.device.api.ui.container.MainScreen;
import java.io.EOFException;
import java.io.IOException;
import java.io.InputStream;
import java.util.Random;
import net.rim.device.api.ui.component.ButtonField; 
import net.rim.device.api.ui.*;  
import net.rim.device.api.ui.component.Dialog;
import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.container.HorizontalFieldManager;




public class app extends UiApplication
{
public static void main(String[] args)
{
app theApp = new app();
theApp.enterEventDispatcher();



}

public app()
{
    pushScreen(new sexfactsScreen());
}

}

final class sexfactsScreen extends MainScreen
{
    public sexfactsScreen()
      {
    	//Set title, create buttons, 
    	setTitle("0000");
 
    	
	
    	ButtonField Truth = new ButtonField("000",ButtonField.CONSUME_CLICK);
    	ButtonField Dare = new ButtonField("000",ButtonField.CONSUME_CLICK);
        final RichTextField text = new RichTextField(100);
        final RichTextField text2 = new RichTextField(5);
        HorizontalFieldManager manger = new HorizontalFieldManager();
        final RichTextField begin = new RichTextField("0000");
       
        
        
     // Get an input stream from the file.
    	InputStream stream = getClass().getResourceAsStream("/bam.txt");

    	if(stream != null)
    	{
    	    LineReader lineReader = new LineReader(stream);                              
    	           
    	    // We read data from input stream one line at a time until we
    	    // reach end of file. Each line is parsed to extract data.  
    	    
    	    //Random number generator
    	    Random dice = new Random();
    	    int num = 0; 
    	    for (int counter=1; counter<=10; counter++){
    	        num = dice.nextInt(10);
    	    }
    	    
    	    for(int i =0;i< num;i++)
    	    {
    	        try
    	        {
    	            String line = new String(lineReader.readLine());
    	            text.setText(line);


    	            	                
    	            // Parse the current line...
    	                            
    	        }
    	        catch(EOFException eof)
    	        {
    	            // We've reached the end of the file.
    	            break;
    	        }
    	        catch(IOException ioe)
    	        {
    	            // Error reading data from file
    	        }               
    	    }
    	    
    	}
    	
    	//Add buttons/Fields
    	
    	  add(begin);
          add(text2);
          add(text);
          manger.add(Truth);
          manger.add(Dare);
          add(manger);
          
          FieldChangeListener customListener = new FieldChangeListener() {   
              public void fieldChanged(Field field, int context) {    
            	  
            	  begin.setText("0000");
            	  
            	  InputStream stream = getClass().getResourceAsStream("/toon.txt");

              	if(stream != null)
              	{
              	    LineReader lineReader = new LineReader(stream);                              
              	           
              	    // We read data from input stream one line at a time until we
              	    // reach end of file. Each line is parsed to extract data.  
              	    
              	    Random dice = new Random();
              	    int num = 0; 
              	    for (int counter=1; counter<=10; counter++){
              	        num = dice.nextInt(46);
              	    }
              	    
              	    for(int i =0;i< num;i++)
              	    {
              	        try
              	        {
              	            String line = new String(lineReader.readLine());
              	            text.setText(line);


              	            	                
              	            // Parse the current line...
              	                            
              	        }
              	        catch(EOFException eof)
              	        {
              	            // We've reached the end of the file.
              	            break;
              	        }
              	        catch(IOException ioe)
              	        {
              	            // Error reading data from file
              	        }               
              	    }
              	    
              	}
          
              	
          
           

             }   
              };   

              FieldChangeListener customListener2 = new FieldChangeListener() {   
                  public void fieldChanged(Field field, int context) {    
                	  
                	  begin.setText("000");
                	  
                	  InputStream stream = getClass().getResourceAsStream("/da.txt");

                  	if(stream != null)
                  	{
                  	    LineReader lineReader = new LineReader(stream);                              
                  	           
                  	    // We read data from input stream one line at a time until we
                  	    // reach end of file. Each line is parsed to extract data.  
                  	    
                  	    Random dice = new Random();
                  	    int num = 0; 
                  	    for (int counter=1; counter<=10; counter++){
                  	        num = dice.nextInt(38);
                  	    }
                  	    
                  	    for(int i =0;i< num;i++)
                  	    {
                  	        try
                  	        {
                  	            String line = new String(lineReader.readLine());
                  	            text.setText(line);


                  	            	                
                  	            // Parse the current line...
                  	                            
                  	        }
                  	        catch(EOFException eof)
                  	        {
                  	            // We've reached the end of the file.
                  	            break;
                  	        }
                  	        catch(IOException ioe)
                  	        {
                  	            // Error reading data from file
                  	        }               
                  	    }
                  	    
                  	}
              
                  	
              
               

                 }   
                  }; 
           
           Truth.setChangeListener(customListener); 
           Dare.setChangeListener(customListener2); 
      
	
       }
    
    public void close()
    {
        // Display a farewell message before closing application.
        Dialog.alert("Goodbye!");     
        super.close();
    }   

    public void paint(Graphics gs) {

    	gs.setBackgroundColor(0x00FF0000); // red background

    	gs.clear();

    	super.paint(gs);

    	}

 

 

Thanks,
Saula
Your neighborhood programmer.
http://homeworkjava.com
Please use plain text.
Developer
Developer
CMY
Posts: 1,122
Registered: ‎02-10-2009
My Device: 8130 / 8350 / 9530 / 9550 / 9850 / PlayBook
My Carrier: Verizon

Re: Painting the WHOLE background

I don't use any of the stock RIM classes, but what is the default color for a manager? Event though you clear the screen, you are still painting the manager/fields over the cleared area.

Please use plain text.