
import java.util.*;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.geometry.Insets;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.layout.GridPane;
import javafx.stage.Stage;
import javafx.scene.control.TextArea;
import javafx.scene.control.TextField;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;

/**
 * This is the main exercises for learning how to use the GUI.
 * To start with, Create buttons that do the following: 
 * Part A 1) add to the count, 2) print hello and 3)double the money each time the button is clicked 
 * Part B 1) 3 Different buttons that add different words tot he word array. 2)A button that prints out everything. 3)A button that emptys out the words array
 * Part C Now, instead of printing hello and the money to the console, create a Label and change the label to the value of money instead. If Hello is clicked, make it say hello!
 * Part D Now setup a TextArea and adjust all system.out.printlns to print to the TextArea instead.
 *
 * @author (your name)
 * @version (a version number or a date)
 */
public class GUI_Intro extends Application
{
    // Variables used for the exercises here
    
    private int count = 0;
    private int money = 1; 
    ArrayList<String> words = new ArrayList<String>();
    
    //Labels are stored up the top so we can keep them in memory!
    private Label myLabel = new Label("0");
    private TextArea textOutput = new TextArea();

    /**
     * The start method is the main entry point for every JavaFX application. 
     * It is called after the init() method has returned and after 
     * the system is ready for the application to begin running.
     *
     * @param  stage the primary stage for this application.
     */
    @Override
    public void start(Stage stage)
    {
        // Create a Buttons
        Button myButton00 = new Button("Button at (0,0)");
        Button myButton13 = new Button("Button at (1,3)");
        Button myButton22 = new Button("Button at (2,2)");
        Button myButton95 = new Button("Button at (9,5)");
        Button sayHello = new Button("Click me to say hello!");
        //YOUR CODE HERE - You may adjust and rename the buttons I have made
        
        //assigning fuctions to buttons.
        sayHello.setOnAction(this::printHello);
        myButton00.setOnAction(this::buttonClick);

        // Create a new grid pane. You will need all of this but you can ignore what they mean.
        GridPane pane = new GridPane();
        pane.setPadding(new Insets(10, 10, 10, 10));
        pane.setMinSize(300, 300);
        pane.setVgap(10);
        pane.setHgap(10);
        //end of ignoring code!
        pane.setGridLinesVisible(true);//comment this out to get rid of the lines.
        
        

        // Add the buttons to the pane.
        pane.add(myButton00, 0, 0);//x, then y co-ordinates
        pane.add(myButton22, 2, 2);
        pane.add(myButton13, 1, 3);
        pane.add(myButton95, 9, 5);
        pane.add(sayHello,4,4);
        
        //Adding the Labels. They are created at the top.
        pane.add(myLabel, 1, 0);//still using x and y cordinates
        
        //Text Area settings
        textOutput = new TextArea();
        textOutput.setText("output text goes here!");
        pane.add(textOutput,0,2,2,3);//the TextArea spans across 2 coordinates. Check the Google Slide for clarifications!


        Scene scene = new Scene(pane, 600,800);//width, height. CHG Note - You may change the size if you wish!
        stage.setTitle("JavaFX Example");
        stage.setScene(scene);

        // Show the Stage (window)
        stage.show();
    }

    /**
     * This will be executed when the button is clicked
     * It increments the count by 1
     */
    private void buttonClick(ActionEvent event)
    {
        // Counts number of button clicks and shows the result on a label
        count = count + 1;
        myLabel.setText("This is the new text for the label");
    }
    
    /**
     * This will be executed when the button is clicked
     * Prints Hello to the console
     */
    private void printHello(ActionEvent event)
    {
        printText("jello");
        System.out.println("hello");
    }
    
    /**
     * Double the money. Then print it out each time it is printed.
     */
    private void printMoney(ActionEvent event)
    {
        // YOUR CODE HERE
    }
    
    /**
     * When this button is clicked, add the word "orange" to the words array
     */
    private void addWord1(ActionEvent event)
    {
        // YOUR CODE HERE
    }
    
    /**
     * When this button is clicked, add the word "cat" to the words array
     */
    private void addWord2(ActionEvent event)
    {
        // YOUR CODE HERE
    }
    
    /**
     * When this button is clicked, add a String of your choice to the words array.
     */
    private void addWord3(ActionEvent event)
    {
        // YOUR CODE HERE
    }
    
    /**
     * When this button is clicked, print out all the words in the words array.
     */
    private void printAllWords(ActionEvent event)
    {
        // YOUR CODE HERE
    }
    
    private void printText(String text){
        textOutput.setText(textOutput.getText() + text + "\n");
    }
    
}
