@Override
  public void actionPerformed(ActionEvent e) {
    // TODO Auto-generated method stub
    if (e.getSource() == backButton) {
      CardLayout cl = (CardLayout) (this.card.getLayout());
      cl.show(this.card, "Menu");
    }

    // browse for source folder in preprocessing
    else if (e.getSource() == selectFolder1) {
      int a = srcFolder.showOpenDialog(this);
      if (a == JFileChooser.APPROVE_OPTION) {
        File file = srcFolder.getSelectedFile();
        folder1.setText(file.getAbsolutePath());
      }
    }
    // browse for destination folder in preprocessing
    else if (e.getSource() == selectDest) {
      int a = destFolder.showOpenDialog(this);
      if (a == JFileChooser.APPROVE_OPTION) {
        File file = destFolder.getSelectedFile();
        destination.setText(file.getAbsolutePath());
      }
    }
    // browse for source folder in train/test
    else if (e.getSource() == selectFolder2) {
      int a = tFolder.showOpenDialog(this);
      if (a == JFileChooser.APPROVE_OPTION) {
        File file = tFolder.getSelectedFile();
        folder2.setText(file.getAbsolutePath());
      }
    }
    // run test/train
    else if (e.getSource() == run) {
      String path = folder2.getText();
      if (train.isSelected()) {

        // reset graph and summary table
        resetResults();
        TrainTask trainTask = new TrainTask(this, path);
        // task.addPropertyChangeListener(this);
        trainTask.execute();
        run.setEnabled(false);

      } else if (test.isSelected()) {
        TestTask testTask = new TestTask(this, path);
        testTask.execute();
        run.setEnabled(false);

      } else if (eval.isSelected()) {
        // read the images
        // p.getAllFeatures2(path, "cross_validation_data");
        task = new Task(this);
        // task.addPropertyChangeListener(this);
        task.execute();
        run.setEnabled(false);
      }
    }
    // crop datasets
    else if (e.getSource() == crop) {
      String sourcePath = folder1.getText().replace("\\", "/") + "/";
      String destinationPath = destination.getText().replace("\\", "/") + "/";
      p.cropImages(setList.getSelectedIndex() + 1, sourcePath, destinationPath);
    } else if (e.getSource() == viewResults) {
      resultsDialog.setVisible(true);
    } else if (e.getSource() == viewConfButton) {
      d.setVisible(true);
    }

    // show confusion matrix
    else if (e.getSource() == viewANN) {
      // change color of button
      viewANN.setColor("orange");
      viewSVM.setColor("blue");
      viewBN.setColor("blue");

      this.fillConfTable(evalANN.confusionMatrix());
    } else if (e.getSource() == viewSVM) {

      viewSVM.setColor("orange");
      viewBN.setColor("blue");
      viewANN.setColor("blue");
      this.fillConfTable(evalSVM.confusionMatrix());
    } else if (e.getSource() == viewBN) {
      viewBN.setColor("orange");
      viewANN.setColor("blue");
      viewSVM.setColor("blue");
      this.fillConfTable(evalNB.confusionMatrix());
    }
  }
  private void addComponents() {
    // preprocess panel components
    pPanel = new JPanel();
    pPanel.setBounds(20, 150, 310, 180);
    pPanel.setLayout(null);
    this.add(pPanel);

    heading2 = new JLabel("Preprocessing");
    heading2.setBounds(100, 5, 100, 30);
    pPanel.add(heading2);

    selectData = new JLabel("Select Dataset:");
    selectData.setBounds(50, 30, 100, 30);
    pPanel.add(selectData);
    String[] list = {"1", "2", "3", "4", "5", "6"};
    setList = new JComboBox(list);
    setList.setBounds(150, 30, 80, 25);
    pPanel.add(setList);

    sLabel = new JLabel("Select source folder:");
    sLabel.setBounds(40, 55, 150, 25);
    pPanel.add(sLabel);

    folder1 = new JTextField(10);
    folder1.setBounds(40, 75, 120, 25);
    pPanel.add(folder1);

    selectFolder1 = new ClassyButton("Browse", "white");
    selectFolder1.setBounds(170, 75, 100, 25);
    pPanel.add(selectFolder1);

    dLabel = new JLabel("Select destination folder:");
    dLabel.setBounds(40, 95, 200, 25);
    pPanel.add(dLabel);

    destination = new JTextField(10);
    destination.setBounds(40, 115, 120, 25);
    pPanel.add(destination);

    selectDest = new ClassyButton("Browse", "white");
    selectDest.setBounds(170, 115, 100, 25);
    pPanel.add(selectDest);

    crop = new ClassyButton("Crop", "blue");
    crop.setBounds(100, 145, 95, 30);
    pPanel.add(crop);

    srcFolder = new JFileChooser();
    srcFolder.setCurrentDirectory(new java.io.File("."));
    srcFolder.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);

    destFolder = new JFileChooser();
    destFolder.setCurrentDirectory(new java.io.File("."));
    destFolder.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);

    // train and test panel components
    tPanel = new JPanel();
    tPanel.setBounds(20, 340, 310, 210);
    //		tPanel.setBackground(Color.red);
    tPanel.setLayout(null);
    this.add(tPanel);

    status = new JLabel("");
    // status.setBackground(Color.red);
    status.setBounds(30, 10, 250, 30);
    tPanel.add(status);

    train = new JRadioButton("Train");
    test = new JRadioButton("Test");
    eval = new JRadioButton("Evaluate Models");
    ButtonGroup group = new ButtonGroup();
    group.add(train);
    group.add(test);
    group.add(eval);
    GridLayout layout = new GridLayout(1, 0);
    JPanel radioPanel = new JPanel();
    //  train.setBounds(0,0 , 10, 30);
    radioPanel.add(train);
    radioPanel.add(test);
    radioPanel.add(eval);

    radioPanel.setBounds(35, 15, 250, 30);
    tPanel.add(radioPanel);

    tFolder = new JFileChooser();
    tFolder.setCurrentDirectory(new java.io.File("."));
    tFolder.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);

    folder2 = new JTextField(10);
    folder2.setBounds(15, 55, 120, 25);
    tPanel.add(folder2);

    selectFolder2 = new ClassyButton("Browse", "white");
    selectFolder2.setBounds(140, 55, 60, 25);
    selectFolder2.setMargin(new java.awt.Insets(0, 2, 0, 2));
    tPanel.add(selectFolder2);

    run = new ClassyButton("Run", "blue");
    run.setBounds(210, 55, 90, 25);
    tPanel.add(run);

    console = new JTextArea();
    console.setEditable(false);
    console.setMargin(new java.awt.Insets(5, 5, 5, 5));
    JScrollPane scrolltextArea = new JScrollPane(console);
    scrolltextArea.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);

    scrolltextArea.setBounds(10, 90, 290, 100);
    tPanel.add(scrolltextArea);

    selectFolder1.addActionListener(this);
    selectFolder2.addActionListener(this);
    selectDest.addActionListener(this);
    run.addActionListener(this);
    crop.addActionListener(this);

    resultsPanel = new JPanel();
    resultsPanel.setLayout(new CardLayout());

    predictedPanel = new JPanel();
    predictedPanel.setLayout(null);
    // initialize table
    Image image;
    try {
      image = ImageIO.read(new File("images/data2/result_0.jpg"));
      ImageIcon imageIcon = new ImageIcon(image);
      String[] columnNames = {"Image", "Acutal", "ANN", "SVM", "NB"};
      Object[] row = {imageIcon, "", "", "", ""};
      Object[][] data = {row};
      TableModel model = new DefaultTableModel(data, columnNames);
      resultsTable =
          new JTable(model) {
            //  Returning the Class of each column will allow different
            //  renderers to be used based on Class
            public Class getColumnClass(int column) {
              return getValueAt(0, column).getClass();
            }
          };
      resultsTable.setRowHeight(60);
      TableColumnModel columnModel = resultsTable.getColumnModel();
      columnModel.getColumn(0).setPreferredWidth(80);
      columnModel.getColumn(1).setPreferredWidth(25);
      columnModel.getColumn(2).setPreferredWidth(25);
      columnModel.getColumn(3).setPreferredWidth(25);
      columnModel.getColumn(4).setPreferredWidth(25);
      resultsTable.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);
      JScrollPane scroll = new JScrollPane(resultsTable);
      scroll.setBounds(5, 5, 385, 380);
      predictedPanel.add(scroll);

    } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }

    // create panel for confusion matrix
    cPanel = new JPanel();
    cPanel.setLayout(null);

    cTable =
        new JTable(NUM_CLASSES + 1, NUM_CLASSES + 1) {
          @Override
          public Component prepareRenderer(TableCellRenderer renderer, int row, int col) {
            Component comp = super.prepareRenderer(renderer, row, col);
            Object value = getModel().getValueAt(row, col);
            // if (getSelectedRow() == row) {
            if (col == 0) {
              comp.setBackground(Color.LIGHT_GRAY);
            } else if (row + 1 == col) {
              comp.setBackground(Color.GREEN);
            } else {
              comp.setBackground(Color.white);
            }

            if (getSelectedRow() == row) {
              if (row + 1 == col) {
                comp.setBackground(Color.GREEN);
              } else {
                comp.setBackground(Color.lightGray);
              }
            }
            return comp;
          }
        };
    TableColumn column = null;
    for (int i = 0; i <= NUM_CLASSES; i++) {
      column = cTable.getColumnModel().getColumn(i);
      if (i == 0) {
        column.setPreferredWidth(50); // sport column is bigger
      } else {
        column.setPreferredWidth(30);
      }
    }

    JScrollPane scroll2 =
        new JScrollPane(
            cTable,
            JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
            JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    cTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
    // scroll2.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);

    scroll2.setBounds(50, 70, 1100, 550);
    cPanel.add(scroll2);

    viewANN = new ClassyButton("ANN", "blue");
    viewSVM = new ClassyButton("SVM", "orange");
    viewBN = new ClassyButton("NB", "blue");

    viewANN.setBounds(400, 20, 100, 30);
    viewSVM.setBounds(550, 20, 100, 30);
    viewBN.setBounds(700, 20, 100, 30);

    viewANN.addActionListener(this);
    viewSVM.addActionListener(this);
    viewBN.addActionListener(this);

    d = new JDialog();
    d.setLayout(null);
    d.setTitle("Confusion Matrices");
    d.setSize(new Dimension(1200, 700));
    Container c = d.getContentPane();

    c.setBackground(Color.WHITE);
    d.add(scroll2);

    d.add(viewANN);
    d.add(viewSVM);
    d.add(viewBN);

    resultsDialog = new JDialog();
    // resultsDialog.setLayout(null);
    resultsDialog.setTitle("Confusion Matrices");
    resultsDialog.setSize(new Dimension(800, 700));
    c = resultsDialog.getContentPane();

    pGraphPanel = new JFXPanel();
    Platform.runLater(
        new Runnable() {
          @Override
          public void run() {
            final CategoryAxis xAxis = new CategoryAxis();
            final NumberAxis yAxis = new NumberAxis(0, 100, 10);
            xAxis.setLabel("Word");
            yAxis.setLabel("Recognition rate (%)");
            lineChart = new LineChart<String, Number>(xAxis, yAxis);

            for (int i = 0; i < 3; i++) {
              XYChart.Series series = new XYChart.Series();
              switch (i) {
                case 0:
                  series.setName("ANN");
                  break;
                case 1:
                  series.setName("SVM");
                  break;
                case 2:
                  series.setName("NB");
                  break;
              }
              for (int j = 0; j < NUM_CLASSES; j++) {
                series.getData().add(new XYChart.Data(wordClasses[j], 0));
              }
              lineChart.getData().add(series);
            }

            lineChart.getStylesheets().add("chart.css");
            Scene scene = new Scene(lineChart, 800, 600);
            pGraphPanel.setScene(scene);
          }
        });
    // pGraphPanel.setBounds(20,20,700,400);
    c.add(pGraphPanel);

    // create panel and table for accuracy results
    aPanel = new JPanel();
    aPanel.setLayout(null);
    String[] columnNames = {
      "Word",
      "ANN Precision",
      "ANN Recall",
      "SVM Precision",
      "SVM Recall",
      "BN Precision",
      "BN Recall"
    };
    Object[] row = {"", "", "", "", "", "", ""};
    Object[][] data = {row};
    TableModel model = new DefaultTableModel(data, columnNames);
    accuracyTable = new JTable(model);
    JScrollPane scroll3 = new JScrollPane(accuracyTable);
    scroll3.setBounds(5, 240, 380, 200);
    // aPanel.add(scroll3);

    String[] columnNames2 = {" ", "ANN", "SVM", "NB"};
    Object[][] data2 = {
      {"ACCURACY", "", "", ""}, {"BUILD TIME", "", "", ""}, {"RECALL", "", "", ""}
    };
    model = new DefaultTableModel(data2, columnNames2);
    TableModel model2 = new DefaultTableModel(data2, columnNames2);
    summaryTable = new JTable(model2);
    JScrollPane scroll4 = new JScrollPane(summaryTable);
    scroll4.setBounds(10, 250, 380, 70);
    aPanel.add(scroll4);

    viewConfButton = new ClassyButton("View Confusion Matrix", "blue");
    viewConfButton.setBounds(200, 350, 180, 30);
    viewConfButton.addActionListener(this);
    aPanel.add(viewConfButton);

    viewResults = new ClassyButton("View all results", "blue");
    viewResults.setBounds(20, 350, 160, 30);
    viewResults.addActionListener(this);
    aPanel.add(viewResults);

    aGraphPanel = new JFXPanel();
    Platform.runLater(
        new Runnable() {
          @Override
          public void run() {
            xAxis = new CategoryAxis();
            yAxis = new NumberAxis(0, 100, 10);
            bc = new BarChart<String, Number>(xAxis, yAxis);
            bc.setTitle("Recognition Rate Comparison");
            xAxis.setLabel("ML");
            yAxis.setLabel("Recognition rate");
            scene = new Scene(bc, 320, 200);
            XYChart.Series series1 = new XYChart.Series();
            series1.getData().add(new XYChart.Data(ann, 2));
            series1.getData().add(new XYChart.Data(svm, 3));
            series1.getData().add(new XYChart.Data(nb, 6));
            bc.getData().add(series1);
            //  bc.setStyle("CHART_COLOR_1: #e9967a;");

            bc.getStylesheets().add("chart.css");
            aGraphPanel.setScene(scene);
          }
        });

    aGraphPanel.setBackground(Color.green);
    aGraphPanel.setBounds(20, 20, 360, 200);
    aPanel.add(aGraphPanel);

    // System.out.println(aGraphPanel.getScene().rootProperty());
    resultsPanel.add(aPanel, "Accuracy");
    // resultsPanel.add(cPanel, "Confusion");
    resultsPanel.add(predictedPanel, "Predicted");
    resultsPanel.setBounds(350, 150, 400, 400);
    this.add(resultsPanel);

    //		CardLayout cl = (CardLayout)(this.card.getLayout());
    //        cl.show(this.card, "Document");

  }