package xmp_eventLoop;

import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;

public class Button implements Runnable {
	String label;
	String actionCommand;
	ArrayList<ActionListener> actionListeners;
	int actionID;

	public Button(String label) {
		this.label=label;
		this.actionCommand=label;
		actionListeners=new ArrayList<ActionListener>();
		actionID=ActionEvent.ACTION_FIRST;
		System.out.println("Button: New button created with label: " + label);
	}
	
	public void paint(Graphics graphics) {
		System.out.println("Render Button graphics now.");
		// graphics.drawChars(label.toCharArray(), 0, 0, 0, 0);
	}
	
	public void addActionListener(ActionListener callback) {
		actionListeners.add(callback);
	}
	
	public void setActionCommand(String ac) { 
		actionCommand=ac;
	}

	@Override
	public void run() {
		System.out.println("Button with label: " + label + " pressed... calling all action listeners.");
		ActionEvent event = new ActionEvent(this,actionID++,actionCommand);
		for(ActionListener cb : actionListeners) cb.actionPerformed(event);
	}

}
