Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

problem of showing immutable image that will be out of frame

  Asked By: Violet    Date: May 10    Category: Java    Views: 780
  

want to show a immutable image on my phone it will be shown out of frame


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


public class ImmutableImage extends MIDlet {
private Display display;
private MyCanvas canvas;
public ImmutableImage(){
display = Display.getDisplay(this);
canvas = new MyCanvas(this);
}
public void startApp() {
display.setCurrent(canvas);
}

public void pauseApp() {
}
protected void exitAction(){
destroyApp(true);
notifyDestroyed();
}
public void destroyApp(boolean unconditional) {
}
class MyCanvas extends Canvas implements CommandListener{
private ImmutableImage immutableImage;
private Command exit;
private Image image = null;
public MyCanvas(ImmutableImage immutableImage){
this.immutableImage = immutableImage;
exit=new Command("Exit",Command.EXIT,1);
addCommand(exit);
setCommandListener(this);

try{

image=image.createImage("/james.png");

}catch(Exception e){
Alert alert=new Alert("failure", "Cant open image file",
null,null);
alert.setTimeout(Alert.FOREVER);
alert.setType(AlertType.ERROR);
display.setCurrent(alert);
}
}
protected void paint(Graphics graphics) {

if(image!=null){
graphics.setColor(255,255,255);
graphics.fillRect(0,0,getWidth(),getHeight());
graphics.drawImage(image,getWidth(),getHeight(),
graphics.LEFT|Graphics.TOP);

}
}

public void commandAction(Command command, Displayable displayable) {
if(command == exit){
immutableImage.exitAction();
}
}


}
}

Share: 

 

3 Answers Found

 
Answer #1    Answered By: Camille Garrett     Answered On: May 10

graphics.drawImage( image,getWidth( ),getHeight( ), graphics.LEFT| Graphics. TOP);
will draw the image  at the bottom right coner of the screen ,thats why its going off the screen.
try this : graphics.drawImage( image,20,20, graphics.LEFT| Graphics. TOP); or some other coordinates inside the boundiers of the screen and works for you.

 
Answer #2    Answered By: Olivia Campbell     Answered On: May 10

Can't get your problem. You are drawing image  out of screen.
graphics.drawImage(
image,getWidth(),getHeight(),
graphics.LEFT|Graphics.TOP);

 
Answer #3    Answered By: Hariz Burki     Answered On: May 10

thanks for replying
yes,when i run this program by my phone  ,the photo will get out of the screen but as you know when you open  a photo by your phone default image  viewer ,the photo will be shown   completely in the screen, but whit this program, just some part of whole will be shown and the other parts will be out of the screen

 




Tagged: