|
This J2ME tip illustrates how To use CustomItem. A CustomItem is
customizable by subclassing to introduce new visual and interactive
elements into Forms. Subclasses are responsible for their visual
appearance including sizing and rendering and choice of colors, fonts and
graphics.Subclasses are responsible for the user interaction mode by
responding to events generated by keys, pointer actions, and traversal
actions.
public class CustomItemDemo extends MIDlet implements CommandListener
{
private Display display;
private Command exit;
Form frm;
private MyCustomItem item;
public DateFieldDemo()
{
//Create a DateField
item =new MyCustomItem();
display = Display.getDisplay(this);
}
public void startApp()
{
frm=new Form("DateField Demo");
exit= new Command("Exit",Command.EXIT,1);
frm.addCommand(exit);
frm.setCommandListener(this);
//Add CustomItem to displayable
frm.setTicker(item);
frm.append("#####");
display.setCurrent(frm);
}
public void pauseApp()
{
}
public void destroyApp(boolean un)
{
}
public void commandAction(Command cmd,Displayable d)
{
if(cmd==exit) {
}
}
}
class MyCustomItem extends CustomItem
{
int count=0;
public void paint(Graphics g, int w, int h)
{
g.drawString("Hello from JJKK :"+count,10,10);
//Paint ur own stuff here
}
protected int getPrefContentHeight(int width)
{
return 100;
}
protected int getPrefContentWidth(int height)
{
return 100;
}
protected int getMinContentHeight()
{
return 50;
}
protected int getMinContentWidth()
{
return 50;
}
protected void keyPressed(int keyCode)
{
//write ur code here to do stuff
count++;
}
}
|
Related Tips
|
Page 1 of 0 ( 0 comments )
You can share your information about this topic using the form below!
Please do not post your questions with this form! Thanks.