BlackBerry Forums Support Community
              

Closed Thread
 
LinkBack Thread Tools
Old 11-24-2009, 12:25 AM   #1 (permalink)
New Member
 
Join Date: Aug 2009
Model: 8310
PIN: N/A
Carrier: Vodafone
Posts: 1
Post Thanks: 0
Thanked 0 Times in 0 Posts
Thumbs up Displaying Custom field screen.

Please Login to Remove!

Hi

I am new to Blackberry developement, i m trying to develop the custom fields & use them in my application.

I have developed simple LabelField & tried using it , but its not displaying in the screen.

I am creating the instance of CLabelField & adding it to VerticalFieldManager & then manager to DemoScreen, which extends MainScreen.

So pls look into the issue & let me know the problem.

If there are any free third party Custom fields with good look, are available pls let me know.

I am attaching my source code, pls have a look at this & let me know the problem.

/**
*
*/
package com.khan.uiApp;

import net.rim.device.api.ui.UiApplication;
import com.khan.screens.DemoScreen;

/**
* @author Hidayath
*
*/
public class CustomFieldsDemo extends UiApplication{


public CustomFieldsDemo()
{
System.out.println("CustomFieldsDemo.CustomFieldsD emo()");
pushScreen(new DemoScreen());
}
/**
* @param args
*/
public static void main(String[] args) {
System.out.println("CustomFieldsDemo.main()");
CustomFieldsDemo demo = new CustomFieldsDemo();
demo.enterEventDispatcher();
}

}



=========================


/**
*
*/
package com.khan.screens;

import net.rim.device.api.ui.container.MainScreen;
import net.rim.device.api.ui.container.VerticalFieldManag er;

import com.khan.customFields.CLabelField;
/**
* @author Hidayath
*
*/
public class DemoScreen extends MainScreen{

private CLabelField uName;
private VerticalFieldManager vfm;
public DemoScreen()
{
System.out.println("DemoScreen.DemoScreen()");
super.setTitle("Demo Screen");
vfm = new VerticalFieldManager();
uName = new CLabelField("Hidayath", 50,100);
uName.setDimensions(50, 20);
vfm.add(uName);
add(vfm);
// add(uName);

}

}


=================


/**
*
*/
package com.khan.customFields;

import net.rim.device.api.ui.component.LabelField;
import net.rim.device.api.ui.Color;
import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.Font;
import net.rim.device.api.ui.Graphics;


/**
* @author Hidayath
*
*/
public class CLabelField extends Field {

public static final int OFFSET=5;
private String label;
private int xPos, yPos;
private int _labelHeight;
private int _labelWidth;
private Font _font;

public CLabelField(String label, int xPos, int yPos) {
System.out.println("CLabelField.CLabelField()");
this.label = label;
this.xPos = xPos;
this.yPos = yPos;
}

public void setDimensions(int width, int height) {
this._labelWidth = width;
this._labelHeight = height;
}

protected void layout(int width, int height) {
// Update the cached font - in case it has been changed.
System.out.println("CLabelField.layout()");
_font = getFont();
_labelHeight = _font.getHeight();
_labelWidth = _font.getAdvance(this.label);

// Calc width.
System.out.println("bwidth ::"+width+" height::"+height);
width = Math.min(width, getPreferredWidth());

// Calc height.
height = Math.min(height, getPreferredHeight());

System.out.println("width ::"+width+" height::"+height);
// Set dimensions.
setExtent(width, height);
}

protected void paint(Graphics g)
{
System.out.println("CLabelField.paint()");
// g.setBackgroundColor(Color.BLUE);
g.setColor(Color.BLUE);
g.fillRect(this.xPos, this.yPos, this._labelWidth, this._labelWidth);
g.setColor(Color.WHITE);
g.drawText(this.label, this.xPos+OFFSET, this.yPos+OFFSET);
}

public int getPreferredWidth() {
return this._labelWidth;
}

public int getPreferredHeight() {
return this._labelHeight;
}
}




Thanks
Hidayath
Offline  
Closed Thread


Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

LF13333N NOS National Semiconductor
$8.99
LF13333N NOS National Semiconductor pictureLH0024CH NOS National Semiconductor
$14.99
LH0024CH NOS National Semiconductor pictureLH0033CG NOS National Semiconductor
$16.99
LH0033CG NOS National Semiconductor picture1981 Archer Radio Shack Semiconductor Replacement Guide 276-4004
$12.0
1981 Archer Radio Shack Semiconductor Replacement Guide 276-4004 pictureFREESCALE SEMICONDUCTOR PBS12C128SLK NI ELVIS PROTOTYPE BOARD LEARNING KIT
$99.99
FREESCALE SEMICONDUCTOR PBS12C128SLK NI ELVIS PROTOTYPE BOARD LEARNING KIT picture






Copyright 2004-2016 BlackBerryForums.com.
The names RIM and BlackBerry are registered Trademarks of BlackBerry Inc.