/** * Copyright 2006 Jeffrey Palm. * * This is GPLed, don't use it to fly airplanes. */ import java.io.*; import java.awt.*; import java.util.*; import javax.swing.*; import javax.swing.event.*; public class DarthAcc { public static void main(String[] args) { try { new DarthAcc().realMain(args); } catch (Exception e) {handle(e);} } static void handle(Exception e) {e.printStackTrace();} public void realMain(String[] args) throws Exception { // Default options String ams = "/Applications/AMSTracker"; // Read the arguments for (int i=0; i]"); System.exit(0); } else if ("-ams".equals(arg)) { ams = args[i++]; } else { System.err.println("Invalid argument: " + arg); } } // Launch the tater JFrame f = new JFrame(); final Image darth = Toolkit.getDefaultToolkit().getImage(getClass().getClassLoader().getSystemResource("DarthAcc.jpg")); final Point pnt = new Point(); final int acc[] = new int[2]; // x,y directions final JPanel p = new JPanel() { {this.setBackground(Color.white);} public void paint(Graphics g) { g.setColor(Color.white); g.fillRect(0,0,getWidth(),getHeight()); g.drawImage(darth,(int)pnt.getX(),(int)pnt.getY(),Color.white,this); g.setColor(Color.black); g.drawString("x,y:" + ((int)pnt.getX()) + "," + ((int)pnt.getY()),getWidth()-100,getHeight()-60); g.drawString("acc:" + acc[0] + "," + acc[1],getWidth()-100,getHeight()-30); } }; f.getContentPane().add(p); p.setPreferredSize(new Dimension(700,700)); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.pack(); f.setVisible(true); // Start the process String[] cmd = {ams, "-u", ".1", "-s"}; Process proc = Runtime.getRuntime().exec(cmd); final BufferedReader in = new BufferedReader(new InputStreamReader(proc.getInputStream())); final boolean[] going = new boolean[]{true}; Thread t = new Thread(new Runnable() { public void run() { while (going[0]) { try { String line = in.readLine(); if (line.indexOf("AMS") != -1) continue; StringTokenizer st = new StringTokenizer(line," \n\t\r",false); int x = Integer.parseInt(st.nextToken().trim()); int y = Integer.parseInt(st.nextToken().trim()); System.err.println("x="+x + "," + "y="+y); acc[0] = -x; acc[1] = y; pnt.translate(acc[0],acc[1]); p.repaint(); } catch (Exception e) {handle(e);} } } }); t.start(); proc.waitFor(); going[0] = false; proc.exitValue(); t.join(); } }