ALLInterview.com :: Home Page KalAajKal.com
 Advertise your Business Here     
Browse  |   Placement Papers  |   Company  |   Code Snippets  |   Certifications  |   Visa Questions
Post Question  |   Post Answer  |   My Panel  |   Search  |   Articles  |   Topics  |   ERRORS new
   Refer this Site  Refer This Site to Your Friends  Site Map  Bookmark this Site  Set it as your HomePage   interview questions urls   External Links  Contact Us     Login  |  Sign Up                      
info       Did you received any Funny E-Mails from your Friends and like to share with rest of our friends? Yeah!! you can post that stuff   HERE
Google
 
Categories  >>  Software  >>  Java Related  >>  J2ME
 
 


 

 
 Java J2EE interview questions  Java J2EE Interview Questions
 J2ME interview questions  J2ME Interview Questions
 Java Related AllOther interview questions  Java Related AllOther Interview Questions
Question
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.
 Question Submitted By :: Shiva034
I also faced this Question!!     Rank Answer Posted By  
 
  Re: 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
# 1
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 ?    0 Yes 0 No
Shelly
 
  Re: 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
# 2
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 ?    0 Yes 0 No
Susanta Mandal
 
 
 

 
 
 
Other J2ME Interview Questions
 
  Question Asked @ Answers
 
What is JSR ?  1
Describe and explain WMLScript ?  1
What is the difference between CLDC 1.0 and CLDC 1.1?  4
What is EDGE ?  1
Explain i-appli ?  1
What is RMI ?  2
Explain HTTPS ?  1
What is JCP ?  1
Describe and explain VLR ?  1
Describe and explain UDDI ?  1
What is Mobitex ?  1
What is Foundation Profile ?  1
What is PCS ?  1
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.  2
What is MIDlet suite ?  1
What is Provisioning ?  1
What is kXML ?  1
What is WAE ?  1
What is PNG ?  1
What is PDC ?  1
 
For more J2ME Interview Questions Click Here 
 
 
 
 
 
   
Copyright Policy  |  Terms of Service  |  Help  |  Site Map 1  |  Articles  |  Site Map  |   Site Map  |  Contact Us
   
Copyright © 2007  ALLInterview.com.  All Rights Reserved.

ALLInterview.com   ::  Forum9.com   ::  KalAajKal.com