import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.ArrayList;

public class AppleTreeGUI extends JFrame  {
    private Timer timer = new Timer(1000, new TimerAction());
    private static final String APPLEA = "Apple Picker A";
    private static final String APPLEB = "Apple Picker B";
    private AppleTree appleTree = new AppleTree();
    private DrawTree treePanel;
		
		
	
    public AppleTreeGUI() {
	treePanel = new DrawTree(appleTree);
	setUpFrame();
	timer.start();
    }
	
    private void setUpFrame() {
	getContentPane().add(treePanel, BorderLayout.CENTER);
	addbuttons();
	setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setSize(600, 600);
	//pack();
        setVisible(true);
       
    }
	
	
    private void addbuttons() {
	JPanel buttonPanel = new JPanel();
	ButtonListener bl = new ButtonListener();
	JButton apples1 = new JButton(APPLEA);
	buttonPanel.add(apples1);
	apples1.addActionListener(bl);
		
	JButton applesB = new JButton(APPLEB);
	buttonPanel.add(applesB);
	applesB.addActionListener(bl);
		
	getContentPane().add(buttonPanel, BorderLayout.SOUTH);
    }
	
    private class  TimerAction implements  ActionListener, Runnable {
	public void actionPerformed(ActionEvent e) {
	    Thread t = new Thread(this);
	    t.start();
	}

	// growApples
	public void run() {
	    appleTree.growApples(treePanel);
	}
    }
	
    private class  ButtonListener implements  ActionListener, Runnable {
		
	public void actionPerformed(ActionEvent e) {
	    Thread t = new Thread(this);
	    t.start();
	}
	// growApples
	public void run() {
	    appleTree.pickApples(treePanel);
	}
    }
	
    public static void main(String[] args)  {
	new AppleTreeGUI();
    }
}
