package xmp_eventLoop;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class Tester implements Runnable,ActionListener {

	public void run() {
		System.out.println("Tester run method invoked");
		Button exitButton=new Button("Exit");
		exitButton.setActionCommand("Enough!");
		System.out.println("Tester run adding Tester to exitButton as an action listener");
		exitButton.addActionListener(this);
		// Normally, this would occur automatically, but we are eliding too much
		exitButton.paint(null); 
		// Simulate the pressing of the exit button
		System.out.println("Tester run method simulating press of exitButton.");
		EventLoop.EVENTLOOP.addEvent(exitButton);
		
	}

	@Override
	public void actionPerformed(ActionEvent e) {
		System.out.println("Tester: actionPerformed callback invoked with action: " + e);
		if (e.getActionCommand().equals("Enough!")) {
			System.out.println("Tester: actionPerformed requesting exit from the event loop.");
			EventLoop.EVENTLOOP.requestExit();
		}
		
	}
	
	public static void main(String[] args) {
		Tester tester=new Tester();
		System.out.println("Tester: Starting main function which calls invokeLater");
		EventLoop.invokeLater(tester);	
		System.out.println("End of Tester.main function after calling invokeLater");
	}
}
