import javax.swing.JButton;
import javax.swing.JFrame;

/**
 * Test class for the new ThreadedActionListener
 * 
 * This is an example for you to use as a reference
 * 
 * @author goskab
 *
 */
public class ThreadTester extends JFrame {
	private OswaldInterface oi;
	private JButton toggle;

	/**
	 * Starter method
	 * @param args doesn't do anything
	 */
	public static void main(String[] args) {
		//test out the new action listener
		ThreadTester tr = new ThreadTester();
		tr.setVisible(true);
	}
	
	/**
	 * Start up the extra interface
	 *
	 */
	public ThreadTester() {
		oi = new OswaldInterface();
		this.setLayout(null);
		this.setSize(130, 100);
		
		toggle = new JButton("Run");
		this.add(toggle);
		toggle.setSize(100,50);
		toggle.setLocation(10,10);
		toggle.setVisible(true);
		//Add the new type of action listener
		toggle.addActionListener(new MyActionListener());
		
		this.setVisible(true);
	}
	
	/**
	 * My new super awesome actionListener class
	 * 
	 * NOTE: extends ThreadedActionListener not implements ActionListener
	 * 
	 * This will work on both the oswald and a computer (without blocking guis)
	 * 
	 * @author goskab
	 *
	 */
	public class MyActionListener extends ThreadedActionListener {

		@Override
		public void run() {
			System.out.println("Ran my action Listener");
			//wait for a hit on the oswald
			while (oi.getAccelZ() < 10000) {
				
			}
			System.out.println("Oswald hit!");
		}
		
	}
}
