BackGround color in FORM

Hi friends,Can anybody tel me how to set the background color in form but not using j2me polish. If anybody has the idea please tell me ....
[161 byte] By [anup123a] at [2007-11-26 15:54:14]
# 1

Create a extended class from CustomItem . you will have a bunch of methods to

implements such as paint(Graphics g)...

your paint() method implementation could be:

protected void paint(Graphics arg0, int w, int w) {

g.setColor(Color.BLUE);// choose color here

g.fillRect(0,0,w,h);

// anything else ...

}

see the CustomItem javadoc for more tips on paint method

after, add your BackgroundCustomItem to your Form and you will have a bg to your Form

suparenoa at 2007-7-8 22:14:44 > top of Java-index,Java Mobility Forums,Java ME Technologies...
# 2
can you give the code in detail ? And i want it for the j2me application and also tell where do i find the information abt this topic Thanks in advance.........
anup123a at 2007-7-8 22:14:44 > top of Java-index,Java Mobility Forums,Java ME Technologies...
# 3

sorry but i cannot give you the full code !

if you install your WTK, you can find in the WTK's folder the MIDP api. in this javadoc, you

will infos for:

javax.microedition.lcdui.Form

javax.microedition.lcdui.CustomItem

the only code that i can give you is the start on your CustomItem class

package mypackage;

import javax.microedition.lcdui.*;

/**

* custom class to create a background for a Form.

* @author anup123

* @see CustomItem

*/

public BackgroudFrom extends CustomItem{

// contructor

public BackgroudFrom(int color){

super();

...

}

// unimplemented methods comes below ...

...

}

if you're not a beginner with j2me, now it's easy !

(easier if you work with eclipse and eclipseme !)

good luck

suparenoa at 2007-7-8 22:14:44 > top of Java-index,Java Mobility Forums,Java ME Technologies...
# 4
thanks i am now able to set back color to form but when i am setting any element on that customitem it gives me error . Is it possible to set item on that background color if yes give me idea ......
anup123a at 2007-7-8 22:14:44 > top of Java-index,Java Mobility Forums,Java ME Technologies...
# 5

have you read the midp javadoc?

public class Form

extends Screen

A Form is a Screen that contains an arbitrary mixture of items: images, read-only text fields, editable text fields, editable date fields, gauges, choice groups, and custom items. In general, any subclass of the Item class may be contained within a form. The implementation handles layout, traversal, and scrolling. The entire contents of the Form scrolls together.

[.......]

public abstract class Item

extends Object

A superclass for components that can be added to a Form. All Item objects have a label field, which is a string that is attached to the item. The label is typically displayed near the component when it is displayed within a screen. The label should be positioned on the same horizontal row as the item or directly above the item. The implementation should attempt to distinguish label strings from other textual content, possibly by displaying the label in a different font, aligning it to a different margin, or appending a colon to it if it is placed on the same line as other string content. If the screen is scrolling, the implementation should try to keep the label visible at the same time as the Item.

[.......]

suparenoa at 2007-7-8 22:14:44 > top of Java-index,Java Mobility Forums,Java ME Technologies...
# 6
Thanks buddy for u r help......................
anup123a at 2007-7-8 22:14:44 > top of Java-index,Java Mobility Forums,Java ME Technologies...
# 7
you're welcome
suparenoa at 2007-7-8 22:14:44 > top of Java-index,Java Mobility Forums,Java ME Technologies...
# 8

hi,

i have written the code for making a background for my Form but what i draw in the paint method, but it doesn't take all the form but only the area between two items added in my form. do you manage to draw the all part of your form?

thanks.

public class BackgroudFrom extends CustomItem{

private int hauteur,largeur;

public BackgroudFrom(int color,int x,int y){

super("test");

hauteur=y;

largeur=x;

}

protected int getMinContentWidth() {return largeur;}

protected int getMinContentHeight() {return hauteur;}

protected int getPrefContentWidth(int arg0) {return largeur;}

protected int getPrefContentHeight(int arg0) {return hauteur;}

protected void paint(Graphics g, int x, int y) {

g.setColor(100,50,100);

g.fillRoundRect(0,0,y,x,x/6,y/6);

}

}

and in my midlet:

bg=new BackgroudFrom(0,mc.getWidth(),mc.getHeight());

myForm.append(bg);

myForm.append("Contact :");

stev34a at 2007-7-8 22:14:44 > top of Java-index,Java Mobility Forums,Java ME Technologies...
# 9
Do you Evalutate the canvas solution?Is the better way to obtain customization due to low level programming, form is a high level component
PeppeMEa at 2007-7-8 22:14:44 > top of Java-index,Java Mobility Forums,Java ME Technologies...
# 10

i think there are two ways to customize a form:

- use the class form and adding custom items

but i don't manage to draw in all parts of my form.

- use canvas.

but i believe that we can't add item on canvas..

how can i make a form with a canvas?

i just want to realize a customized form, that include textfileds, image items and a button(i believe it doesn't exist, certainly created by a customitem).

have you an idea for doing this?

thanks.

stev34a at 2007-7-8 22:14:44 > top of Java-index,Java Mobility Forums,Java ME Technologies...
# 11
anup123 seems to have manage to draw all the form.has he really realize what i want, and how has he done?what is the difference between my code?thanks, everybody from the forum....
stev34a at 2007-7-8 22:14:44 > top of Java-index,Java Mobility Forums,Java ME Technologies...