millroy 0 Newbie Poster

hi i am making compass for cellphones well this is the code. the code has 2 classes i for canvas and other for middlet.

middlet code:

import javax.microedition.lcdui.*;

import javax.microedition.midlet.*;

public class CompassPro extends MIDlet implements CommandListener {
    Command Exit=new Command("Exit",Command.EXIT,0);
    bkcanvas base=new bkcanvas();
    Display cell;


    public void startApp() {
    cell=Display.getDisplay(this);
    base.addCommand(Exit);
    base.setCommandListener(this);
    cell.setCurrent(base);

    try{

    }
    catch(Exception ex){}


    }

    public void pauseApp() {
    }

    public void destroyApp(boolean unconditional) {
    }


    public void commandAction(Command c,Displayable d){
    if(c==Exit)
    notifyDestroyed();




    }







}

canvas code:

import java.io.IOException;
import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.*;
import javax.microedition.location.*;

public class bkcanvas extends Canvas implements LocationListener {
Image compass;
Image needle; 
Image bk;
Image gps;
Image nogps;


boolean gpsb;
double rotation;
boolean choice;

LocationProvider lp;
Criteria criteria;


bkcanvas(){
try{
compass=Image.createImage(this.getClass().getResourceAsStream("icon/compass.png"));    
needle=Image.createImage(this.getClass().getResourceAsStream("icon/needle.png"));
bk=Image.createImage(this.getClass().getResourceAsStream("icon/background.png"));
gps=Image.createImage(this.getClass().getResourceAsStream("icon/gps.png"));
nogps=Image.createImage(this.getClass().getResourceAsStream("icon/nogps.png"));
criteria=new Criteria();
criteria.setCostAllowed(true);
criteria.setSpeedAndCourseRequired(true);
criteria.setPreferredPowerConsumption(Criteria.POWER_USAGE_HIGH);

try {
            lp = LocationProvider.getInstance(criteria);
            lp.setLocationListener(this, -1, -1, -1);
        }
catch(LocationException le) {
            System.out.println("LOCATION ERROR:" + le.getMessage());
        }   

}
catch(IOException ex){}
}



public void paint(Graphics g){
  g.drawImage(bk, 0, 0, 0);
  g.drawImage(compass, 0, 20,0);  
  rotation(g); 
  gpss(g);

}

public void rotation(Graphics g){
  g.drawImage(needle, 0, 20,0);   
}

public void gpss(Graphics g){
if(gpsb==true)
    g.drawImage(gps, 100, 250,0);
else
    g.drawImage(nogps, 95, 250,0);
}

    public void locationUpdated(LocationProvider lp, Location lctn) {
        if(lctn.isValid()){
            gpsb=true;
            repaint();
         }
        else {
            gpsb=false;
            repaint();        
        }
    }

    public void providerStateChanged(LocationProvider lp, int i) {

    }



}

i have not hull developed i am only testing wheather the gps is function or not wen i tested on my cell phone wave 5253 which uses a-gps it didnot respond.
the responce is determined my the Image gps and nogps

please tell me how to work this out

i also want to know how i can rotate a image at different angles coz its impossible to do so with spirit class

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.20 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.