/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package kanjiflash;

import java.io.File;
import java.net.URL;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Properties;
import java.util.ResourceBundle;
import javafx.application.Application;
import javafx.collections.ObservableList;
import javafx.event.EventHandler;
import javafx.event.EventType;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable;
import javafx.fxml.JavaFXBuilderFactory;
import javafx.scene.Node;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.TextField;
import javafx.scene.input.KeyEvent;
import javafx.stage.Stage;

/**
 *
 * @author Alan
 */
public class KanjiFlash extends Application {
    static public boolean STACK_TRACE = true;
    static public Scene kanjiScene;
    static KanjiFlashController kfCtrl;
    
    public static void main(String[] args) {
        Application.launch(KanjiFlash.class, args);
    }
    
    @Override
    public void start(Stage stage) throws Exception {
        URL location = getClass().getResource("LayoutXML.fxml");
        FXMLLoader fxmlLoader = new FXMLLoader();
        fxmlLoader.setLocation(location);
        fxmlLoader.setBuilderFactory(new JavaFXBuilderFactory());
        Parent root = (Parent) fxmlLoader.load(location.openStream());
//        Parent root = FXMLLoader.load(getClass().getResource("LayoutXML.fxml"));
        kfCtrl = (KanjiFlashController)fxmlLoader.getController();
        kanjiScene = new Scene(root);
        stage.setScene(kanjiScene);
        stage.show();
        kanjiScene.addEventFilter(KeyEvent.KEY_TYPED,
                new EventHandler<KeyEvent>(){
                    @Override
                    public void handle(KeyEvent keyEv){
                        String keyChar = keyEv.getCharacter().substring(0, 1);
                        if (keyChar.contains(" ")){
                            kfCtrl.nextState();
                        }
                        if (keyChar.contains("x") || keyChar.contains("X")){
                            kfCtrl.addError();
                        }
                        if (keyChar.contains("d") || keyChar.contains("D")){
                            kfCtrl.dropError();
                        }
                    }
                });        
    }
    public KanjiFlashController getKFC(){
        return kfCtrl;
    }

}
