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
Developer
nagamallika
Posts: 61
Registered: ‎09-06-2010
My Device: Not Specified

How to make all the fields appear on the blackberry screen exactly at the center

Hi my code is

 

/*
 * FirstScreen.java
 *
 * © <your company here>, 2003-2008
 * Confidential and proprietary.
 */

package Applicationimp;

import net.rim.device.api.system.*;
import net.rim.device.api.ui.*;
import net.rim.device.api.ui.component.*;
import net.rim.device.api.ui.container.*;

 

/**
 *
 */
class FirstScreen extends UiApplication
{
    public static void main(String args[])
    {
        FirstScreen fs = new FirstScreen();
        fs.enterEventDispatcher();
     }
        public FirstScreen()
    {  
   
    pushScreen(new FirstScreen1());
     }
}

 

-----------------------------

/*
 * FirstScreen1.java
 *
 * © <your company here>, 2003-2008
 * Confidential and proprietary.
 */

package Applicationimp;

import net.rim.device.api.system.*;
import net.rim.device.api.ui.*;
import net.rim.device.api.ui.component.*;
import net.rim.device.api.ui.container.*;
import net.rim.device.api.ui.decor.*;
import net.rim.device.api.ui.XYEdges.*;

import net.rim.device.api.ui.container.HorizontalFieldManager.*;
import net.rim.device.api.ui.container.MainScreen.*;
import net.rim.device.api.ui.component.LabelField.*;
import net.rim.device.api.ui.component.EditField.*;
import net.rim.device.api.ui.component.PasswordEditField;
import net.rim.device.api.ui.component.ButtonField.*;
import java.lang.String.*;
import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.Graphics;

 

 

 


/**
 *
 */
class FirstScreen1 extends MainScreen
{
    Border bdr;
    Border bdr1;
   
 
   Bitmap bmp;

       
      
  
 
  
    
    LabelField lbl = new LabelField("UserName:");
      
  /*  protected void layout(int width,int height)
            {
                width = 180;
                height = 20;
             super.layout(width,height);
             super.setExtent(width,height);
         //     super.invalidate(20,220,200,18);
             //   setExtent(250,10);
            }
    }; */
       
      
  EditField edit = new EditField();
     
  /*  protected void layout(int width,int height)
            {
                width = 180;
                height = 20;
             super.layout(width,height);
             super.setExtent(width,height);
         //     super.invalidate(20,220,200,18);
             //   setExtent(250,10);
            }
    }; */
    LabelField lbl1 = new LabelField("Password:");
       
  /*  protected void layout(int width,int height)
            {
                width = 180;
                height = 20;
             super.layout(width,height);
             super.setExtent(width,height);
         //     super.invalidate(20,220,200,18);
             //   setExtent(250,10);
            }
    }; */
    PasswordEditField edit1 = new PasswordEditField();
   
       
   /* protected void layout(int width,int height)
            {
                width = 180;
                height = 20;
             super.layout(width,height);
             super.setExtent(width,height);
         //     super.invalidate(20,220,200,18);
             //   setExtent(250,10);
            }
    }; */
       ButtonField signinbutton = new ButtonField("Signin",ButtonField.CONSUME_CLICK);
          
   /* protected void layout(int width,int height)
            {
                width = 180;
                height = 20;
             super.layout(width,height);
             super.setExtent(width,height);
         //     super.invalidate(20,220,200,18);
             //   setExtent(250,10);
            }
    }; */
  
       FieldChangeListener listener=new FieldChangeListener(){
    public void fieldChanged(Field field,int context)
    {
       
 if(signinbutton.getLabel() == "Signin")
   {
       if((edit.getText().length()==0)||(edit1.getText().length()==0))
      
            Dialog.alert("Please enter your UserName and PassWord");
            else
            UiApplication.getUiApplication().pushScreen(new SecondScreen());
            }
            }
     };   
    
 public FirstScreen1()
    {   
    super();
  
    bdr = BorderFactory.createRoundedBorder(new XYEdges(4,4,4,4));
    bdr1 = BorderFactory.createRoundedBorder(new XYEdges(4,4,4,4));
  
    //edit = new EditField();
     edit.setBorder(bdr);
  //lbl1  = new LabelField("Password:");
    //edit1 = new PasswordEditField();
     edit1.setBorder(bdr);
    bmp = Bitmap.getBitmapResource("untitled11.png");
    Background bfg = BackgroundFactory.createBitmapBackground(bmp);
    //signinbutton = new  ButtonField("Signin",ButtonField.CONSUME_CLICK);
       signinbutton.setBackground(bfg);
       signinbutton.setChangeListener(listener);
    CustomField cf = new CustomField(CustomField.USE_ALL_WIDTH|CustomField.USE_ALL_HEIGHT);
    cf.addlbl(lbl);
    cf.addedit(edit);
    cf.addlbl1(lbl1);
    cf.addedit1(edit1);
    cf.addbutton(signinbutton);
    add(cf);
}
 public boolean onClose() {
        System.exit(0);
        return true;
    }
}
     
---------------------------------------------

 

/*
 * CustomField.java
 *
 * © <your company here>, 2003-2008
 * Confidential and proprietary.
 */

package Applicationimp;

import net.rim.device.api.system.*;
import net.rim.device.api.ui.*;
import net.rim.device.api.ui.component.*;
import net.rim.device.api.ui.container.*;
import net.rim.device.api.ui.component.LabelField.*;
import net.rim.device.api.ui.component.EditField.*;
import net.rim.device.api.ui.component.PasswordEditField;
import net.rim.device.api.ui.component.ButtonField.*;
import net.rim.device.api.ui.Manager.*;
import net.rim.device.api.ui.Keypad;


/**
 *
 */
class CustomField extends Manager
 {
  LabelField lbl;
  EditField edit;
  LabelField lbl1;
  PasswordEditField edit1;
  ButtonField signinbutton;
 
   public  CustomField(long style)
   {   
  
   super(style);
  }
public void addlbl(LabelField username)
{
    lbl = username;
    add(lbl);
}
public void addedit(EditField useredit)
{
    edit = useredit;
    add(edit);
}
public void addlbl1(LabelField password)
{
    lbl1 = password;
    add(lbl1);
}
public void addedit1(PasswordEditField passedit)
{
    edit1 = passedit;
    add(edit1);
}
public void addbutton(ButtonField signbutton)
{
    signinbutton = signbutton;
    add(signinbutton);
}
protected void sublayout(int width,int height)
{
  
    int wid = Display.getWidth()-20;
    int ht = Display.getHeight();
   // int x = 30;
    int lblwid = 0;
    int lblht = 0;
    int editwid = 0;
    int editht = 0;
    int lbl1wid = 0;
    int lbl1ht = 0;
   int edit1wid = 0;
   int edit1ht = 0;
   int signinbuttonwid = 0;
   int signinbuttonht = 0;
   if(lbl != null)
        {
        lblwid =Display.getWidth();
        lblht = Display.getHeight();
        layoutChild(lbl,lblwid,lblht);       
        setPositionChild(lbl,((ht)-(lblht)),(ht/2));
        }
    if(edit != null)
        {
        editwid = Display.getWidth()-lblwid;
        editht = Display.getHeight()-lblht;
        layoutChild(edit,editwid,editht);       
        setPositionChild(edit,((ht)-(editht)),(ht/2));
        }
        if(lbl1 != null)
        {
        lbl1wid = Display.getWidth();
        lbl1ht = Display.getHeight() - lblht;
        layoutChild(lbl1,lbl1wid,lbl1ht);       
       setPositionChild(lbl1,((ht)+(lbl1ht)),(ht/2));
        }
    /*if(edit1 != null)
        {
        edit1wid = Display.getWidth()-lbl1wid;
        edit1ht = Display.getHeight()-lbl1ht;
        layoutChild(edit1,edit1wid,edit1ht);       
        setPositionChild(edit1,((ht)-(edit1ht)),(ht/2));
        }*/
if(signinbutton != null)
        {
        signinbuttonwid =Display.getWidth()-(lbl1wid+edit1wid);
        signinbuttonht =Display.getHeight()-(editht+edit1ht);
        layoutChild(signinbutton,signinbuttonwid,signinbuttonht);       
        setPositionChild(signinbutton,(width-signinbuttonwid),(ht/2));
        }
setExtent(wid,ht);
}
public int getPreferredWidth()
{
    return Display.getWidth();
}
public int getPreferredHeight()
{
    return Display.getHeight();
}

}

----------------------------------------

I wrote custom field code to make my first screen fields to appear at the center but it is not coming properly can any one help me in this.Exactly which method i should implement to get it.


 

Please use plain text.
Developer
nagamallika
Posts: 61
Registered: ‎09-06-2010
My Device: Not Specified

Re: How to make all the fields appear on the blackberry screen exactly at the center

The sublayout method only we should use.What changes i have to do in my code so that my code can run on any blackberry device of any resolution

Please use plain text.
Developer
nagamallika
Posts: 61
Registered: ‎09-06-2010
My Device: Not Specified

Re: How to make all the fields appear on the blackberry screen exactly at the center

Can any one post the solution
Please use plain text.
Developer
ananthasivanvk
Posts: 23
Registered: ‎08-02-2008
My Device: BlackBerry Dev Alpha
My Carrier: Bharti Airtel

Re: How to make all the fields appear on the blackberry screen exactly at the center

Hi You just need to sublayout customField properly. Then it'll come to screen as you expect.
Regards
Anand
Please use plain text.
Developer
nagamallika
Posts: 61
Registered: ‎09-06-2010
My Device: Not Specified

how to add next option to the menu of the blackberry

Hi i've added the buttonfield "next" in my second screen,but i want this next button to be added as an option to the menu of the blackberry so that when i click it ,the third screen should get displayed .How to do this and which class to refer.

 

My code is:

 

-----------------------------------------------

/*
 * SecondScreen.java
 *
 * © <your company here>, 2003-2008
 * Confidential and proprietary.
 */

package Applicationimp;

import net.rim.device.api.system.*;
import net.rim.device.api.ui.*;
import net.rim.device.api.ui.component.*;
import net.rim.device.api.ui.container.*;
import net.rim.device.api.ui.component.CheckboxField;
import net.rim.device.api.ui.container.VerticalFieldManager.*;
import net.rim.device.api.ui.component.LabelField.*;
import net.rim.device.api.ui.component.ButtonField.*;

import net.rim.device.api.ui.Graphics;
import net.rim.device.api.ui.decor.Background.*;

 

/**
 *
 */
class SecondScreen extends MainScreen
 {
    HorizontalFieldManager hfm_empty;
    VerticalFieldManager vfm;
    LabelField lbl2;
    LabelField lbl3;
    LabelField lbl4;
    CheckboxField chk;
    ButtonField button1;
   // Bitmap arrow;
  
   
  LabelField  lbl_top_empty = new LabelField(""){
       
       protected void layout(int width,int height)
            {
                width = 120;
                height =150;
             super.layout(width,height);
             super.setExtent(width,height);
         //     super.invalidate(20,220,200,18);
             //   setExtent(250,10);
            }
    }; 
 
 
    FieldChangeListener listener = new FieldChangeListener(){
      
    public void fieldChanged(Field field,int context)
{
 
    if((button1.getLabel() == "Next") && button1.isEditable() )
    {
        
       UiApplication.getUiApplication().pushScreen(new ThirdScreen());
}
}
};
  
   FieldChangeListener checkbox_lis = new FieldChangeListener(){
      
    public void fieldChanged(Field field,int context)
{
   if(chk.getChecked() == true)
   {
       button1.setEditable(true);
      
    }
    else
    {
        button1.setEditable(false);
    }
      
      
}
};
    public SecondScreen()
    {   
    super();
    setTitle("TERMS AND CONDITIONS");
    hfm_empty = new HorizontalFieldManager(Manager.HORIZONTAL_SCROLL);
     hfm_empty.add(lbl_top_empty);
     add(hfm_empty);
    vfm = new VerticalFieldManager(Manager.VERTICAL_SCROLL);
    lbl2 = new LabelField("Against the laws of violation");
    lbl3 = new LabelField("I agree to the terms and conditions");
    lbl4 = new LabelField("-----------------------------------");
    vfm.add(lbl2);
    vfm.add(lbl3);
    vfm.add(lbl4);
    add(vfm);
    chk = new CheckboxField("I accept",false,Field.FOCUSABLE|Field.EDITABLE);
    chk.setChangeListener(checkbox_lis);
    //add(chk);
    //arrow = Bitmap.getBitmapResource("untitledarrow.PNG");
    //Background bfg1 = BackgroundFactory.createBitmapBackground(arrow);
    button1 = new ButtonField("Next",ButtonField.CONSUME_CLICK|ButtonField.FIELD_RIGHT);
    //button1.setBackground(bfg1);
    button1.setChangeListener(listener);
    button1.setEditable(false);
    add(button1);
   CustomField cf = new CustomField(CustomField.USE_ALL_WIDTH|CustomField.USE_ALL_HEIGHT);
   cf.addCheckbox(chk);
   add(cf);
  
   
}
public boolean onClose()
{
    UiApplication.getUiApplication().pushScreen(new FirstScreen1());
   return true;
}
}

Please use plain text.
Developer
Ekansh
Posts: 468
Registered: ‎08-07-2009
My Device: Curve, Bold, Storm
My Carrier: Blackberry Developer

Re: how to add next option to the menu of the blackberry

hi,

 

You need to override the sublayout method of the manager over which you are adding the fields.

 

 hfmIcon = new MainManager()
        {
            protected void sublayout(int width,int height)
            {

                    layoutChild(b1, getPreferredWidth(), getPreferredHeight());
                    layoutChild(b2, getPreferredWidth(),getPreferredHeight());


                    setPositionChild(b1, 10, 40); 
                    setPositionChild(b2 10, 80);  
                    super.setExtent(width,height);
            }    
                    
        };

 

Regards

Ekansh

----------------------------------------------------------
feel free to press the kudos button on the left side to thank the user that helped you.
please mark posts as solved if you found a solution.
Please use plain text.