I have a problem wtih a program.
The program logic is like this..........
from a class which extends midlet class i create object of
a class(say canobj(word)) which extends canvas class by
passing a string.
the next statement is display.setCurrent(canobj);
Everything is fine but the paint(Graphics g) method is not
executed. What may the problem. please suggest me the
answer.

Answer Posted / shelly

Hey,
check out the following code. See if u get any clue from
this. Your display needs to be initialised first..hope ur
doin tat in ur code.. unless u do tat ur paint wudn't be
called at all. try to display a form instead of a canvas and
see if display is causing the problem. hope this was helpful
to u.



public class Mainscreen extends MIDlet implements
CommandListener{
Display display;
public Mainscreen(){
display = Display.getDisplay(this);
setcommandListener(this);
}
public void startApp(){
Form f = new Form("ShowCanvas"){
f.addCommand(Command.OK);
f.setcommandListener(this);
display.setcurrent(f);
}
}
public void DestroyApp(boolean t){
notifyDestroyed();
}
public void pauseApp(){
}
public void commandAction(Command c ,Displayable d){
if(c==Command.OK){
showDetails();
}
}
}
public void showDetails() {

Canvas canvas = new Canvas() {
protected void paint(Graphics g) {

g.setColor(255, 255, 255);
g.fillRect(0, 0, getWidth(), getHeight());
g.setColor(0, 0, 0);
g.setFont(font_med);
g.drawString("HI anonymous",10, 0, 0);

}
};
canvas.addCommand(Commands.Back);
canvas.setCommandListener(this);
display.setcurrent(canvas);
}

Is This Answer Correct ?    2 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

create a menu which has the following options:cut-can be on/off,copy-can be on/off,paste-can be on/off,delete-can be on/off,select all-put all4 options on,unselect all-put all 4 options off,using event handling in MIDP application

5249


Is there any framework in j2me that supports for all three HTc,iphone,Nokia phones.

1888


11 is a group of specifications for wireless networks developed by the Institute of Electrical and Electronics Engineers (IEEE). 802.11 uses the Ethernet protocol and CSMA/CA (carrier sense multiple access with collision avoidance) for path sharing.

543


Write a Java program to deactivate a cell phone when authentication failed

1735


Give the name of classes of j2se which is not used in j2me

1819






Memory managment technique in j2me

1713


What is j2me in mobile computing?

490


In hyderabad, which s/w training center is best for java, other than corejava what r the new tools to learn in java,which tool is best & have current requirement,pls give me information about java to learn ?

1794


where images can be stored in j2me?

2008


what are all contain highlevel api?

1734


what is the application compatability?

1736


What is amps ?

596


what is the use of wtk?

1554


Memory managment technique in j2me

1799


create a midp application,where user can enter player name and points.the program saves the information to the record using RMS at MIDP device.program should also print out the top 10 player list to the end user.

2909