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 / susanta mandal

With the same flow,the paint(Graphics g) will execute.
If not executes then do not display.setCurrent(canobj) here.
Go to the Canvas class & take a Display object & initialize
it with the MIDlet call display object.Then from the Canvas
class constructor call a method,where first call repaint()
method,then serviceRepaint() method,then call
display.setCurrent(this).It will work like bellow..


import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;

public class TestView extends MIDlet {
CanvasView canObj;
static Display DISPLAY;
public void startApp() {
String word = "Hi Susanta";
DISPLAY = Display.getDisplay(this);
canObj = new CanvasView(word,this);
}

public void pauseApp() {
}

public void destroyApp(boolean unconditional) {
notifyDestroyed();
}
}

class CanvasView extends Canvas implements CommandListener{
Display display;
String str="";
Command exit;
TestView midlet;
public CanvasView(String str,TestView midlet){
this.midlet = midlet;
display = TestView.DISPLAY;
this.str = str;
exit = new Command("Exit",Command.EXIT,0);
addCommand(exit);
setCommandListener(this);
callPaint();
}

protected void paint(Graphics g){
setFullScreenMode(true);
g.setColor(0,0,200);
g.fillRect(getWidth()/2-40,getHeight()/2-20,80,40);
g.setColor(255,255,255);

g.drawString(str,getWidth()/2,getHeight()/2-10,g.HCENTER|g.TOP);
}

public void callPaint(){
repaint();
serviceRepaints();
display.setCurrent(this);
}

public void commandAction(Command command,Displayable disp){
if(command == exit){
midlet.destroyApp(true);
}
}
}

Is This Answer Correct ?    4 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is amps ?

590


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

1809


where images can be stored in j2me?

1996


what is the application compatability?

1727


What is j2me in mobile computing?

480






Memory managment technique in j2me

1708


Memory managment technique in j2me

1787


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.

2899


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

1727


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.

536


what is the use of wtk?

1550


what are all contain highlevel api?

1729


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

1876


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 ?

1785


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

5238