⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 starter.java

📁 read GPS information from the commport installed in PDA
💻 JAVA
字号:
package Reader;


import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.midlet.MIDlet;

/**
 * Test class for GPS. Not needed for application.
 * 
 * @author Dominik Schmidt
 */
public class Starter extends MIDlet implements CommandListener, Runnable {
//	private static final String GPS_BT_URL = "comm:0;baudrate=9000";
	private static final String GPS_BT_URL = "file:///C:\\Users\\Jack\\j2mewtk\\2.5.2\\appdb\\DefaultColorPhone\\filesystem\\root1\\Gps.dat";
//	C:\Users\Jack\j2mewtk\2.5.2\appdb\DefaultColorPhone\filesystem\root1
	

	private Command exitCommand;
	
	private Command pauseCommand;
	
	private Command resumeCommand;

	private Display display;

	private static final long BREAK = 500;

	private Logger nn = new Logger("GPS Test", 512, 0);

	private Thread runner;

	private GPSReader gps;

	public Starter() {
		display = Display.getDisplay(this);
		exitCommand = new Command("Exit", Command.SCREEN, 0);
		pauseCommand = new Command("Pause", Command.SCREEN, 2);
		resumeCommand = new Command("Resume", Command.SCREEN, 2);
	}

	public void startApp() {
//		System.out.print("------------------");
		nn.addCommand(exitCommand);
		nn.addCommand(pauseCommand);
		nn.addCommand(resumeCommand);
		nn.setCommandListener(this);

		display.setCurrent(nn);

		gps = new GPSReader(nn , GPS_BT_URL);
		gps.start();
		start();
	}

	public void pauseApp() {
	}

	public void destroyApp(boolean unconditional) {
		stop();
		gps.stop();
	}

	public void commandAction(Command c, Displayable s) {
		if (c == exitCommand) {
			destroyApp(false);
			notifyDestroyed();
		}
		else if(c == pauseCommand) {
			stop();
			gps.stop();
		}
		else if(c == resumeCommand) {
			start();
			gps.start();
		}
	}

	public void run() {
		while (Thread.currentThread() == runner) {
			try {
				Record record = gps.getRecord();
				nn.setTitle("W: " + record.warning);
			nn.setString(record.dateTimeOfFix + "\n" + record.lattitude
						+ "," + record.longitude + ", " + record.quality + ", "
						+ record.satelliteCount);
			} catch (EmptyBufferException e) {
				nn.setString("No data received yet.");
			}
			try {
				Thread.sleep(BREAK);
			} catch (InterruptedException e) {
			}
		}
	}

	public void start() {
		if (runner == null) {
			runner = new Thread(this);
			runner.start();
		}
	}

	public void stop() {
		runner = null;
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -