Guest User

Untitled

a guest
Aug 21st, 2018
276
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.21 KB | None | 0 0
  1. Editfield scroll fails to reach top in blackberry
  2. et=new EditField("Email-id:","");
  3. pwd=new PasswordEditField("Password:","");
  4.  
  5. ab.add(et,35,110);
  6. ab.add(pwd,35,150);
  7.  
  8. et=new EditField("Email-id:","");
  9. pwd=new PasswordEditField("Password:","") {
  10. protected int moveFocus(int amount, int status, int time) {
  11. int cursorPosition = this.getCursorPosition();
  12. if ((cursorPosition == 0) && (amount < 0)) {
  13. et.setFocus();
  14. return 0;
  15. }
  16. else {
  17. return super.moveFocus(amount, status, time);
  18. }
  19. }
  20. };
  21.  
  22. et=new EditField("Email-id:","");
  23. pwd=new PasswordEditField("Password:","");
  24. HorizontalFieldManager manager = new HorizontalFieldManager();
  25. manager.add(et);
  26. manager.add(pwd);
  27. ab.add(manager, yourX, yourY);
  28.  
  29. public class loginscreen extends MainScreen implements FieldChangeListener {
  30.  
  31. private int deviceWidth = Display.getWidth();
  32. private int deviceHeight = Display.getHeight();
  33. private VerticalFieldManager subManager;
  34. private VerticalFieldManager mainManager;
  35. public long mycolor = 0x00FFFFFF;
  36.  
  37. Screen _screen = home.Screen;
  38. TextField heading = new TextField(Field.NON_FOCUSABLE);
  39.  
  40. TextField username_ef = new TextField();
  41. PasswordEditField password_ef = new PasswordEditField();
  42. CheckboxField rememberpass = new CheckboxField();
  43. public ButtonField login_bt = new ButtonField("Login", ButtonField.CONSUME_CLICK);
  44. public ButtonField register_bt = new ButtonField("Register", ButtonField.CONSUME_CLICK);
  45.  
  46. public loginscreen()
  47. {
  48. super();
  49. final Bitmap backgroundBitmap = Bitmap.getBitmapResource("bgd.png");
  50.  
  51. HorizontalFieldManager hfm = new HorizontalFieldManager(Manager.NO_VERTICAL_SCROLL | Manager.NO_VERTICAL_SCROLLBAR )
  52.  
  53. {
  54.  
  55. protected void sublayout(int width, int height)
  56.  
  57. {
  58.  
  59. Field field;
  60.  
  61. int numberOfFields = getFieldCount();
  62.  
  63. int x = 245;
  64.  
  65. int y = 0;
  66.  
  67. for (int i = 0;i < numberOfFields;i++)
  68.  
  69. {
  70.  
  71. field = getField(i);
  72.  
  73. setPositionChild(field,x,y);
  74.  
  75. layoutChild(field, width, height);
  76.  
  77. x +=_screen.getWidth()-381;
  78.  
  79. y += 0;//l17
  80.  
  81. }
  82.  
  83. width=_screen.getWidth();
  84.  
  85. height=48;//w19
  86.  
  87. setExtent(width, height);
  88.  
  89. }
  90.  
  91. };
  92.  
  93.  
  94. mainManager = new VerticalFieldManager(Manager.NO_VERTICAL_SCROLL | Manager.NO_VERTICAL_SCROLLBAR )
  95. {
  96.  
  97. public void paint(Graphics graphics)
  98. {
  99. graphics.clear();
  100. graphics.drawBitmap(0, 0, deviceWidth, deviceHeight, backgroundBitmap, 0, 0);
  101. super.paint(graphics);
  102. }
  103. };
  104. //this manger is used for adding the componentes
  105. subManager = new VerticalFieldManager(Manager.VERTICAL_SCROLL | Manager.VERTICAL_SCROLLBAR )
  106. {
  107. protected void sublayout( int maxWidth, int maxHeight )
  108. {
  109. int displayWidth = deviceWidth;
  110. int displayHeight = deviceHeight;
  111.  
  112. super.sublayout( displayWidth, displayHeight);
  113. setExtent( displayWidth, displayHeight);
  114. }
  115.  
  116. public void paint(Graphics graphics)
  117.  
  118. {
  119. graphics.setColor((int) mycolor);
  120. super.paint(graphics);
  121.  
  122. }
  123. };
  124.  
  125.  
  126. username_ef.setLabel("Username: ");
  127. password_ef.setLabel("Password: ");
  128. rememberpass.setLabel("Remember Password");
  129. heading.setLabel("Please enter your credentials: ");
  130.  
  131. username_ef.setMaxSize(8);
  132. password_ef.setMaxSize(20);
  133.  
  134. subManager.add(heading);
  135. subManager.add(username_ef);
  136. subManager.add(password_ef);
  137. subManager.add(rememberpass);
  138. subManager.add(new SeparatorField());
  139. login_bt.setChangeListener(this);
  140. register_bt.setChangeListener(this);
  141.  
  142. hfm.add(login_bt);
  143. hfm.add(register_bt);
  144. subManager.add(hfm);
  145.  
  146. mainManager.add(subManager);
  147. this.add(mainManager);
  148.  
  149. }
  150.  
  151. public boolean onSavePrompt()
  152. {
  153. return true;
  154. }
  155.  
  156.  
  157. public void fieldChanged(Field field, int context) {
  158. // TODO Auto-generated method stub
  159. if(field == login_bt)
  160. {
  161. //do your code for login button click
  162. }
  163.  
  164. if(field == register_bt)
  165. {
  166. //code for register button click
  167. }
  168. }}
  169.  
  170. // inside MainScreen constructor
  171. add(new EditField("Username:","",0));
  172. add(new EditField("Password:","",0));
  173. add(new ButtonField(buttonBMP,ButtonField.CONSUME_CLICK));
Add Comment
Please, Sign In to add comment