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

Native Development

Reply
New Contributor
evontechdehradun
Posts: 8
Registered: ‎08-24-2012
My Carrier: Airtel

Re: How to create text box and buttons.....

/* * Divyanshu Srivastava * * © , 2011 * Confidential and proprietary. */ package src.com.ui; import net.rim.device.api.system.Display; import net.rim.device.api.system.Bitmap; import net.rim.device.api.ui.Color; import net.rim.device.api.ui.FieldChangeListener; import net.rim.device.api.ui.Graphics; import net.rim.device.api.ui.Manager; import net.rim.device.api.ui.UiApplication; import net.rim.device.api.ui.component.BitmapField; import net.rim.device.api.ui.component.ButtonField; import net.rim.device.api.ui.component.CheckboxField; import net.rim.device.api.ui.component.Dialog; import net.rim.device.api.ui.component.LabelField; import net.rim.device.api.ui.component.PasswordEditField; import net.rim.device.api.ui.component.TextField; import net.rim.device.api.ui.container.HorizontalFieldManager; import net.rim.device.api.ui.container.MainScreen; import net.rim.device.api.ui.container.VerticalFieldManager; import src.com.main.Main; import src.com.util.HttpConnect; import src.com.util.HttpMultipartRequest; import src.com.util.MyUtility; import src.com.util.PersistStoreHandler; public class LoginScreen extends MainScreen implements FieldChangeListener { Bitmap myBitmap; HorizontalFieldManager h1,form1,h2,header,header1,header2,header3,header4,header5,header6,header7,header8; VerticalFieldManager form,form2; Bitmap backgroundBitmap,myBit,myBit1,myBit2,myBit3,myBit4,myBit5,myBit6,myBit7,myBit8,myBit9,myBit10; BitmapField field,field1,field2,field3,field4,field5,field6,field7,field8,field9; PersistStoreHandler persistHandler; CustomButtonField button,button1,temp; // Utility utility=Utility.getUtilityObject(); MyUtility utility=MyUtility.getUtilityObject(); String message,str; HttpMultipartRequest req; LabelField label; CheckboxField checkbox,checkbox1; LabelField username,password,interfac; TextField usttxt; PasswordEditField pwdfield; Main main; public LoginScreen(Main objMain) { super(); main=objMain; persistHandler=PersistStoreHandler.getPersistStoreHandlerInstance(); backgroundBitmap = Bitmap.getBitmapResource(MyUtility.getImageSplashPath()+"/00_SplashScreen.png"); form= new VerticalFieldManager(Manager.USE_ALL_WIDTH |Manager.VERTICAL_SCROLL) { protected void paintBackground(Graphics graphics) { //graphics.setBackgroundColor(0x4C3B17); graphics.setColor(Color.BLACK); super.paint(graphics); graphics.clear(); } public void paint(Graphics graphics) { //graphics.drawBitmap(0, 0, MyUtility.screenWidth,MyUtility.screenHeight, backgroundBitmap, 0, 0); super.paint(graphics); } }; //################################## FORM 1 // form1= new VerticalFieldManager(Manager.USE_ALL_WIDTH | Manager.VERTICAL_SCROLL); HorizontalFieldManager upperTopBar1=new HorizontalFieldManager(Manager.USE_ALL_WIDTH) { protected void paintBackground(Graphics graphics) { graphics.setBackgroundColor(0x90C8AF); super.paint(graphics); graphics.clear(); } protected void subLayout(int maxWidth,int maxHeight) { super.sublayout(MyUtility.screenWidth,MyUtility.screenHeight); setExtent(MyUtility.screenWidth,MyUtility.screenHeight); } } ; if(MyUtility.screenWidth==640){ upperTopBar1.add(MyUtility.getSpacer(250,40)); }else if(MyUtility.screenWidth==320){ upperTopBar1.add(MyUtility.getSpacer(130,40)); }else if(MyUtility.screenWidth==360){ upperTopBar1.add(MyUtility.getSpacer(140,40)); } else{ upperTopBar1.add(MyUtility.getSpacer(190,40)); } upperTopBar1.add(new LabelField("Login",LabelField.USE_ALL_WIDTH|LabelField.FIELD_HCENTER)); //upperTopBar1.add(MyUtility.getSpacer(40,30)); form.add(upperTopBar1); //################################# form1=new HorizontalFieldManager(); form2= new VerticalFieldManager(Manager.USE_ALL_WIDTH) { protected void paintBackground(Graphics graphics) { graphics.setColor(Color.GRAY); super.paint(graphics); //graphics.clear(); } protected void subLayout(int maxWidth,int maxHeight) { super.sublayout(MyUtility.screenWidth,MyUtility.screenHeight); setExtent(MyUtility.screenWidth,MyUtility.screenHeight); } /*public void paint(Graphics graphics) { graphics.drawBitmap(0, 0,MyUtility.screenWidth,MyUtility.screenHeight, backgroundBitmap, 0, 0); super.paint(graphics); } */ }; username=new LabelField("User :",LabelField.FIELD_HCENTER); header1=new HorizontalFieldManager(); header2=new HorizontalFieldManager(); usttxt = new TextField(TextField.FOCUSABLE) { protected void layout(int width,int height) { super.layout(width, height); setExtent(280,35); } protected void paintBackground(Graphics graphics) { graphics.setBackgroundColor(Color.BROWN); graphics.setColor(Color.RED); super.paint(graphics); } protected void paint(Graphics graphics) { graphics.drawRect(0,0,280,35); graphics.setColor(Color.RED); super.paint(graphics); } }; if(utility.username!=""){ usttxt.setText(utility.username); } header1.add(MyUtility.getSpacer(1,35)); header1.add(username); header2.add(MyUtility.getSpacer(1,35)); header2.add(usttxt); password=new LabelField("Password :"); pwdfield = new PasswordEditField("", "") { protected void layout(int width,int height) { super.layout(width, height); setExtent(280,30); } protected void paintBackground(Graphics graphics) { graphics.setBackgroundColor(Color.BROWN); graphics.setColor(Color.RED); super.paint(graphics); } protected void paint(Graphics graphics) { graphics.drawRect(0,0,280,30); graphics.setColor(Color.RED); super.paint(graphics); } }; if(utility.password!=""){ pwdfield.setText(utility.password); } header3=new HorizontalFieldManager(); header3.add(MyUtility.getSpacer(1,30)); header3.add(password); header4=new HorizontalFieldManager(); header4.add(MyUtility.getSpacer(1,30)); header4.add(pwdfield); header5=new HorizontalFieldManager(); checkbox=new CheckboxField("Forget Password",false); header5.add(MyUtility.getSpacer(1,30)); header5.add(checkbox); header6=new HorizontalFieldManager(); checkbox1=new CheckboxField("Remember Me",true); header6.add(MyUtility.getSpacer(1,30)); header6.add(checkbox1); header7=new HorizontalFieldManager(); button = new CustomButtonField("Login",ButtonField.CONSUME_CLICK); button.setChangeListener(this); button1 = new CustomButtonField("Register",ButtonField.CONSUME_CLICK); button1.setChangeListener(this); header7.add(MyUtility.getSpacer(1,30)); header7.add(button); header7.add(MyUtility.getSpacer(15,5)); header7.add(button1); LabelField samp=new LabelField(""); HorizontalFieldManager header8=new HorizontalFieldManager(); header8.add(samp); //header7.add(MyUtility.getSpacer(40,50)); form2.add(MyUtility.getSpacer(1,30)); //form2.add(MyUtility.getSpacer(60,26)); form2.add(header1); form2.add(header2); form2.add(MyUtility.getSpacer(1,5)); form2.add(header3); form2.add(header4); form2.add(MyUtility.getSpacer(1,25)); form2.add(header5); form2.add(header6); form2.add(MyUtility.getSpacer(1,15)); form2.add(header7); //form2.add(MyUtility.getSpacer(60,1)); form2.add(header8); if(MyUtility.screenWidth==640) { System.out.println("DIVYANSHU SRIVASTAVA11111"); form1.add(MyUtility.getSpacer(190,1)); } else if(MyUtility.screenWidth==320) { System.out.println("DIVYANSHU SRIVASTAVA2222"); form1.add(MyUtility.getSpacer(25,1)); }else if(MyUtility.screenWidth==480) { System.out.println("DIVYANSHU SRIVASTAVA2222"); form1.add(MyUtility.getSpacer(80,1)); } else{ System.out.println("DIVYANSHU SRIVASTAVA3333"); form1.add(MyUtility.getSpacer(50,1)); } form1.add(form2); form.add(form1); add(form); } public void fieldChanged(net.rim.device.api.ui.Field field,int status) { System.out.println("SCREEN WIDTH::::::::::::::::::"+Display.getWidth()); System.out.println("SCREEN WIDTH::::::::::::::::::"+Display.getHeight()); CustomButtonField temp=(CustomButtonField)field; if(temp==button) { if(checkbox.getChecked()==true) { if(usttxt.getText().trim().length()==0){ Dialog.alert("Enter the user name"); return; } try{ main.getUiApplication().invokeLater(new Runnable() { public void run() { main.showScreen(main.forgotpasswordId); } } ); } catch(Exception e) { System.out.println(""+e.getMessage()); } return; } if(usttxt.getText().trim().length()>0&& pwdfield.getText().trim().length()>0) { try { Thread t=new Thread() { public void run() { utility.inter=str; try{ HttpConnect hr=new HttpConnect(); String response=hr.makeRequest("http://www.YOURSTORING URL.com/Mob_API/GetLogin.aspx?username="+usttxt.getText().trim()+"&password="+pwdfield.getText().trim()); if(utility.flag==0) { try { UiApplication.getUiApplication().invokeLater(new Runnable() { public void run() { main.showScreen(main.errorScreenId); } }); }catch(Exception e) { } } else if(response.trim().indexOf("true")!=-1) { utility.i=1; utility.name=usttxt.getText(); utility.password=pwdfield.getText(); utility.username=usttxt.getText(); } }catch(Exception e) { } try { if(utility.i==1) { if(checkbox1.getChecked()==true) { persistHandler.setContents(utility.key,utility.name); persistHandler.setContents(utility.key1,utility.password); persistHandler.setContents(utility.key2,utility.username); } else { persistHandler.setContents(utility.key,null); persistHandler.setContents(utility.key1,null); persistHandler.setContents(utility.key2,null); } try{ main.getUiApplication().invokeLater(new Runnable() { public void run() { main.showScreen(main.homeScreenId); } }); } catch(Exception e) { System.out.println(""+e.getMessage()); } } else if(utility.flag==1) { main.getUiApplication().invokeLater(new Runnable() { public void run() { Dialog.alert("User name or Password is Wrong"); } }); } }catch(Exception e) { } } }; t.start(); } catch(Exception e) { } }else { Dialog.alert("User name or password is empty"); } } else if(temp==button1) { main.showScreen(main.registerScreenId); } } class CustomListener implements FieldChangeListener { public void fieldChanged(net.rim.device.api.ui.Field field,int status) { System.out.println("TYhis ios a custom litebffjhnad"); } } public boolean onClose() { Dialog.alert("Exit"); System.exit(0); return true; } }

Please use plain text.
Regular Contributor
janaknayangaljanak
Posts: 55
Registered: ‎05-30-2011
My Carrier: Airtel

Re: How to create text box and buttons.....

This is the java code but i'm working for playbook application development using native sdk. :smileysad:

Please use plain text.
BlackBerry Development Advisor (Retired)
mgoulet
Posts: 329
Registered: ‎05-07-2012
My Carrier: N/A

Re: How to create text box and buttons.....

Hey evontechdehradun,

Can you post your code using the "Code Block"? It makes it more readable.
Thanks!
Martin

Please use plain text.