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
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
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.
[.......]
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 :");
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.