import javax.microedition.midlet.*; import javax.microedition.lcdui.*; import com.kddi.system.*; public class GPSReader extends MIDlet implements CommandListener { GPSCanvas gpsCanvas; Command exitCommand, gpsCommand; Display display; public GPSReader() { display = Display.getDisplay(this); exitCommand = new Command("Exit",Command.EXIT,1); gpsCommand = new Command("GPS",Command.SCREEN,1); gpsCanvas = new GPSCanvas(); gpsCanvas.setCommandListener(this); gpsCanvas.addCommand(exitCommand); gpsCanvas.addCommand(gpsCommand); display.setCurrent(gpsCanvas); } public void startApp(){ } public void pauseApp(){ } public void destroyApp(boolean unconditional){ } public void commandAction(Command command,Displayable screen) { if(command==exitCommand){ destroyApp(false); notifyDestroyed(); } if(command==gpsCommand){ gpsCanvas.showLocation(); } } public class GPSCanvas extends Canvas { Location location; String latitude = "", longitude = ""; Font font; int width, height; public GPSCanvas() { font = Font.getFont(Font.FACE_MONOSPACE,Font.STYLE_PLAIN,Font.SIZE_SMALL); width = getWidth(); height = getHeight(); } public void showLocation() { location = GpsLocation.getLocation(); latitude = location.getLat(); longitude = location.getLon(); repaint(); } public void paint(Graphics g) { g.setColor(255,255,200); g.fillRect(0,0,width,height); g.setColor(0,0,0); g.setFont(font); g.drawString("位置取得結果",width/2,30,Graphics.HCENTER | Graphics.VCENTER ); g.drawString(latitude,width/2,50,Graphics.HCENTER | Graphics.VCENTER ); g.drawString(longitude,width/2,70,Graphics.HCENTER | Graphics.VCENTER ); } } }