com.smanempat.view.ViewClassification.java Source code

Java tutorial

Introduction

Here is the source code for com.smanempat.view.ViewClassification.java

Source

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.smanempat.view;

import com.smanempat.controller.ControllerClassification;
import java.awt.Cursor;
import java.io.IOException;
import java.text.DecimalFormat;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.SwingWorker;
import javax.swing.table.DefaultTableModel;
//import org.jfree.chart.ChartFactory;
//import org.jfree.chart.ChartFrame;
//import org.jfree.chart.ChartPanel;
//import org.jfree.chart.JFreeChart;
//import org.jfree.chart.plot.CategoryPlot;
//import org.jfree.chart.plot.PlotOrientation;
//import org.jfree.data.category.DefaultCategoryDataset;

/**
 *
 * @author Zakaria Andy S
 */
public class ViewClassification extends javax.swing.JInternalFrame {

    /**
     * Creates new form ViewClassification2
     */
    public ViewClassification() {
        initComponents();
        setLocation(15, 20);
        initialization();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jTabbedPane1 = new javax.swing.JTabbedPane();
        jPanel1 = new javax.swing.JPanel();
        buttonProses = new javax.swing.JButton();
        jYearChooser1 = new com.toedter.calendar.JYearChooser();
        jYearChooser2 = new com.toedter.calendar.JYearChooser();
        txtFileDirectory = new javax.swing.JTextField();
        jButton1 = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        txtNumberOfK = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        labelPilihFile = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        tablePreview = new javax.swing.JTable();
        buttonReset = new javax.swing.JButton();
        labelPesanError = new javax.swing.JLabel();
        labelJumlahData = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jCheckBox1 = new javax.swing.JCheckBox();
        txtNilaiUN = new javax.swing.JTextField();
        jLabel9 = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        txtNilaiPT = new javax.swing.JTextField();
        jLabel11 = new javax.swing.JLabel();
        txtThreshold = new javax.swing.JTextField();
        jLabel12 = new javax.swing.JLabel();
        jLabel13 = new javax.swing.JLabel();
        jPanel2 = new javax.swing.JPanel();
        jScrollPane2 = new javax.swing.JScrollPane();
        tableResult = new javax.swing.JTable();
        buttonSimpan = new javax.swing.JButton();
        buttonReClass = new javax.swing.JButton();
        jPanel5 = new javax.swing.JPanel();
        jLabel4 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        labelSiswaIPA = new javax.swing.JLabel();
        labelSiswaIPS = new javax.swing.JLabel();
        labelKeterangan = new javax.swing.JLabel();
        jButton5 = new javax.swing.JButton();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();

        setClosable(true);
        setIconifiable(true);
        setTitle("Klasifikasi Penjurusan Siswa");
        setFrameIcon(
                new javax.swing.ImageIcon(getClass().getResource("/com/smanempat/image/title-klasifikasi.png"))); // NOI18N
        setPreferredSize(new java.awt.Dimension(1340, 697));

        buttonProses.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        buttonProses.setIcon(
                new javax.swing.ImageIcon(getClass().getResource("/com/smanempat/image/button-procces.png"))); // NOI18N
        buttonProses.setText("Proses Klasifikasi");
        buttonProses.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonProsesActionPerformed(evt);
            }
        });

        jButton1.setIcon(
                new javax.swing.ImageIcon(getClass().getResource("/com/smanempat/image/button-browse.png"))); // NOI18N
        jButton1.setText("Browse...");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jLabel1.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabel1.setText("/");

        jLabel2.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jLabel2.setText("Number of Nearest Neighbor (k) : ");

        txtNumberOfK.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtNumberOfKActionPerformed(evt);
            }
        });
        txtNumberOfK.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txtNumberOfKKeyTyped(evt);
            }
        });

        jLabel3.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jLabel3.setText("Tahun Ajaran :");

        labelPilihFile.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        labelPilihFile.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        labelPilihFile.setText("Pilih File :");

        tablePreview.setModel(new javax.swing.table.DefaultTableModel(new Object[][] {

        }, new String[] { "NIS", "NAMA", "JK", "UN", "PT B.INDO", "PT MTK", "PT B.ING", "PT IPA", "MINAT" }));
        jScrollPane1.setViewportView(tablePreview);

        buttonReset.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        buttonReset.setIcon(
                new javax.swing.ImageIcon(getClass().getResource("/com/smanempat/image/button-reset.png"))); // NOI18N
        buttonReset.setText("Reset");
        buttonReset.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonResetActionPerformed(evt);
            }
        });

        labelPesanError.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        labelPesanError.setForeground(new java.awt.Color(204, 0, 0));
        labelPesanError.setText("<<Tampil Pesan Error>>");

        labelJumlahData.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        labelJumlahData.setForeground(new java.awt.Color(0, 153, 51));
        labelJumlahData.setText("0 Data");

        jLabel5.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jLabel5.setText("Jumlah Data : ");

        jCheckBox1.setText("Kriteria Manual");
        jCheckBox1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCheckBox1ActionPerformed(evt);
            }
        });

        txtNilaiUN.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtNilaiUNActionPerformed(evt);
            }
        });
        txtNilaiUN.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                txtNilaiUNKeyReleased(evt);
            }

            public void keyTyped(java.awt.event.KeyEvent evt) {
                txtNilaiUNKeyTyped(evt);
            }
        });

        jLabel9.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jLabel9.setText("Bobot Nilai UN :");

        jLabel10.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jLabel10.setText("Bobot Nilai Placement Test :");

        txtNilaiPT.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtNilaiPTActionPerformed(evt);
            }
        });
        txtNilaiPT.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txtNilaiPTKeyTyped(evt);
            }
        });

        jLabel11.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jLabel11.setText("Threshold :");

        txtThreshold.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtThresholdActionPerformed(evt);
            }
        });
        txtThreshold.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txtThresholdKeyTyped(evt);
            }
        });

        jLabel12.setText("%");

        jLabel13.setText("%");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(jPanel1Layout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel1Layout.createSequentialGroup().addGroup(jPanel1Layout
                        .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(jPanel1Layout.createSequentialGroup().addGap(18, 18, 18)
                                .addGroup(jPanel1Layout
                                        .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addGroup(jPanel1Layout.createSequentialGroup().addComponent(buttonProses)
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                .addComponent(buttonReset))
                                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 1289,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addGroup(jPanel1Layout.createSequentialGroup().addGroup(jPanel1Layout
                                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(jPanel1Layout.createSequentialGroup().addGap(38, 38, 38)
                                        .addComponent(labelPilihFile).addGap(6, 6, 6)
                                        .addComponent(txtFileDirectory, javax.swing.GroupLayout.PREFERRED_SIZE, 203,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGap(6, 6, 6).addComponent(jButton1))
                                .addGroup(jPanel1Layout.createSequentialGroup().addContainerGap()
                                        .addComponent(jLabel3)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(jYearChooser1, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGap(6, 6, 6).addComponent(jLabel1).addGap(6, 6, 6)
                                        .addComponent(jYearChooser2, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(jPanel1Layout
                                        .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(jCheckBox1)
                                        .addGroup(jPanel1Layout.createSequentialGroup().addComponent(jLabel2)
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                .addComponent(txtNumberOfK, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                        85, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                .addComponent(labelPesanError))))
                        .addGroup(jPanel1Layout.createSequentialGroup().addGap(38, 38, 38).addComponent(jLabel5)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(labelJumlahData, javax.swing.GroupLayout.PREFERRED_SIZE, 76,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jLabel9)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(txtNilaiUN, javax.swing.GroupLayout.PREFERRED_SIZE, 52,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jLabel12)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(jLabel10)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(txtNilaiPT, javax.swing.GroupLayout.PREFERRED_SIZE, 52,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jLabel13)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(jLabel11)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(txtThreshold, javax.swing.GroupLayout.PREFERRED_SIZE, 64,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addContainerGap(1514, Short.MAX_VALUE)));
        jPanel1Layout.setVerticalGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel1Layout.createSequentialGroup().addGroup(jPanel1Layout
                        .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING,
                                jPanel1Layout.createSequentialGroup().addGap(4, 4, 4).addComponent(jCheckBox1))
                        .addGroup(jPanel1Layout.createSequentialGroup().addGroup(jPanel1Layout
                                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(jPanel1Layout.createSequentialGroup().addGap(2, 2, 2)
                                        .addGroup(jPanel1Layout
                                                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                .addComponent(jYearChooser1, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                        26, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addComponent(jLabel1).addComponent(jYearChooser2,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE, 26,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE)))
                                .addGroup(jPanel1Layout.createSequentialGroup().addContainerGap()
                                        .addComponent(jLabel3)))
                                .addGap(6, 6, 6)))
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(jPanel1Layout.createSequentialGroup().addGap(5, 5, 5)
                                        .addComponent(labelPilihFile))
                                .addComponent(txtFileDirectory, javax.swing.GroupLayout.PREFERRED_SIZE, 23,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGroup(jPanel1Layout.createSequentialGroup().addGap(1, 1, 1)
                                        .addGroup(jPanel1Layout
                                                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                .addGroup(jPanel1Layout
                                                        .createParallelGroup(
                                                                javax.swing.GroupLayout.Alignment.BASELINE)
                                                        .addComponent(jLabel2)
                                                        .addComponent(txtNumberOfK,
                                                                javax.swing.GroupLayout.PREFERRED_SIZE,
                                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                                        .addComponent(labelPesanError))
                                                .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 23,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE))))
                        .addGap(19, 19, 19)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(jPanel1Layout
                                        .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                        .addComponent(jLabel12)
                                        .addComponent(txtNilaiUN, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(jLabel9).addComponent(jLabel5).addComponent(labelJumlahData))
                                .addGroup(jPanel1Layout
                                        .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                        .addComponent(txtThreshold, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(jLabel11))
                                .addGroup(jPanel1Layout
                                        .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                        .addComponent(jLabel10)
                                        .addComponent(txtNilaiPT, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(jLabel13)))
                        .addGap(5, 5, 5)
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 456,
                                javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(buttonProses, javax.swing.GroupLayout.PREFERRED_SIZE, 41,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(buttonReset, javax.swing.GroupLayout.PREFERRED_SIZE, 41,
                                        javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addContainerGap(51, Short.MAX_VALUE)));

        jTabbedPane1.addTab("Klasifikasi Jurusan Siswa", jPanel1);

        tableResult.setModel(new javax.swing.table.DefaultTableModel(new Object[][] {

        }, new String[] { "NIS", "Nama", "JK", "UN", "PT BINDO", "PT MTK", "PT BING", "PT IPA", "MINAT",
                "JURUSAN" }));
        jScrollPane2.setViewportView(tableResult);

        buttonSimpan.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        buttonSimpan
                .setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/smanempat/image/button-save.png"))); // NOI18N
        buttonSimpan.setText("Simpan");
        buttonSimpan.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonSimpanActionPerformed(evt);
            }
        });

        buttonReClass.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        buttonReClass.setIcon(
                new javax.swing.ImageIcon(getClass().getResource("/com/smanempat/image/button-reclass.png"))); // NOI18N
        buttonReClass.setText("Klasifikasi Ulang");
        buttonReClass.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonReClassActionPerformed(evt);
            }
        });

        jPanel5.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Detail Klasifikasi",
                javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION,
                javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 12))); // NOI18N

        jLabel4.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel4.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel4.setText("Siswa Terklasifikasi Jurusan IPS :");

        jLabel6.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel6.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel6.setText("Siswa Terklasifikasi Jurusan IPA :");

        labelSiswaIPA.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        labelSiswaIPA.setText("0");

        labelSiswaIPS.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        labelSiswaIPS.setText("0");

        labelKeterangan.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        labelKeterangan.setText(
                "Hasil Klasifikasi Penjurusan Siswa Pada Tahun Ajaran <<tahun ajaran>>, dengan paramater K = <<nilai k>> adalah sebagai berikut :");

        jButton5.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jButton5.setIcon(
                new javax.swing.ImageIcon(getClass().getResource("/com/smanempat/image/button-chart.png"))); // NOI18N
        jButton5.setText("Tampilkan Grafik");
        jButton5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton5ActionPerformed(evt);
            }
        });

        jLabel7.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel7.setText("Siswa");

        jLabel8.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel8.setText("Siswa");

        javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
        jPanel5.setLayout(jPanel5Layout);
        jPanel5Layout.setHorizontalGroup(jPanel5Layout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel5Layout.createSequentialGroup().addGroup(jPanel5Layout
                        .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(jPanel5Layout.createSequentialGroup().addGap(22, 22, 22)
                                .addComponent(labelKeterangan))
                        .addGroup(jPanel5Layout.createSequentialGroup().addGap(46, 46, 46)
                                .addGroup(jPanel5Layout
                                        .createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                        .addComponent(jLabel6)
                                        .addGroup(jPanel5Layout
                                                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                .addComponent(jButton5).addComponent(jLabel4)))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addGroup(jPanel5Layout
                                        .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addGroup(jPanel5Layout.createSequentialGroup().addComponent(labelSiswaIPS)
                                                .addGap(18, 18, 18).addComponent(jLabel8))
                                        .addGroup(jPanel5Layout.createSequentialGroup().addComponent(labelSiswaIPA)
                                                .addGap(18, 18, 18).addComponent(jLabel7)))))
                        .addContainerGap(1672, Short.MAX_VALUE)));
        jPanel5Layout.setVerticalGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel5Layout.createSequentialGroup().addContainerGap()
                        .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                .addGroup(jPanel5Layout.createSequentialGroup().addComponent(labelKeterangan)
                                        .addGap(18, 18, 18).addComponent(jLabel6)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                        .addComponent(jLabel4))
                                .addGroup(jPanel5Layout
                                        .createSequentialGroup()
                                        .addGroup(jPanel5Layout
                                                .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                                .addComponent(labelSiswaIPA).addComponent(jLabel7))
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                        .addGroup(jPanel5Layout
                                                .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                                .addComponent(labelSiswaIPS).addComponent(jLabel8))))
                        .addGap(27, 27, 27).addComponent(jButton5)
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)));

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(jPanel2Layout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(buttonSimpan, javax.swing.GroupLayout.PREFERRED_SIZE, 141,
                                javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(14, 14, 14).addComponent(buttonReClass)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED).addComponent(jPanel5,
                                javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE,
                                Short.MAX_VALUE))
                .addGroup(jPanel2Layout.createSequentialGroup().addComponent(jScrollPane2,
                        javax.swing.GroupLayout.PREFERRED_SIZE, 1316, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(0, 0, Short.MAX_VALUE)));
        jPanel2Layout.setVerticalGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 403,
                                javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(jPanel2Layout
                                        .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                        .addComponent(buttonSimpan).addComponent(buttonReClass,
                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                                .addComponent(jPanel5, javax.swing.GroupLayout.PREFERRED_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(0, 76, Short.MAX_VALUE)));

        jTabbedPane1.addTab("Hasil Klasifikasi Jurusan Siswa", jPanel2);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(jTabbedPane1, javax.swing.GroupLayout.PREFERRED_SIZE,
                        javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE));
        layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup().addGap(5, 5, 5).addComponent(jTabbedPane1,
                        javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE,
                        javax.swing.GroupLayout.PREFERRED_SIZE)));

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton5ActionPerformed
        // TODO add your handling code here:
        ControllerClassification controllerClassification = new ControllerClassification();
        controllerClassification.showChart(labelSiswaIPA, labelSiswaIPS, labelKeterangan);
    }//GEN-LAST:event_jButton5ActionPerformed

    private void buttonSimpanActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonSimpanActionPerformed
        try {
            // TODO add your handling code here:
            ControllerClassification controllerClassification = new ControllerClassification();
            controllerClassification.saveResultFile(jYearChooser1, jYearChooser2, tableResult);
        } catch (IOException ex) {
            Logger.getLogger(ViewClassification.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_buttonSimpanActionPerformed

    private void buttonReClassActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonReClassActionPerformed
        // TODO add your handling code here:
        txtNumberOfK.requestFocus();
        DefaultTableModel tabModeRes = (DefaultTableModel) tableResult.getModel();
        tabModeRes.setRowCount(0);
        buttonSimpan.setEnabled(false);
        buttonReClass.setEnabled(false);
        jPanel5.setVisible(false);
        jTabbedPane1.setSelectedIndex(0);
    }//GEN-LAST:event_buttonReClassActionPerformed

    private void txtThresholdKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtThresholdKeyTyped
        // TODO add your handling code here:
    }//GEN-LAST:event_txtThresholdKeyTyped

    private void txtThresholdActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtThresholdActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_txtThresholdActionPerformed

    private void txtNilaiPTKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtNilaiPTKeyTyped
        // TODO add your handling code here:
    }//GEN-LAST:event_txtNilaiPTKeyTyped

    private void txtNilaiPTActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtNilaiPTActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_txtNilaiPTActionPerformed

    private void txtNilaiUNKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtNilaiUNKeyTyped

    }//GEN-LAST:event_txtNilaiUNKeyTyped

    private void txtNilaiUNActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtNilaiUNActionPerformed
        // TODO add your handling code here:
        txtNilaiPT.setText((100 - Integer.parseInt(txtNilaiUN.getText())) + "");
        txtThreshold.requestFocus();
    }//GEN-LAST:event_txtNilaiUNActionPerformed

    private void jCheckBox1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckBox1ActionPerformed
        // TODO add your handling code here:
        if (jCheckBox1.isSelected()) {
            txtNilaiUN.setEnabled(true);
            txtThreshold.setEnabled(true);
            txtNumberOfK.setEnabled(false);
        } else {
            if (txtFileDirectory.getText().equals("") == false) {
                txtNumberOfK.requestFocus();
                txtNumberOfK.setEnabled(true);
            }
            txtNilaiUN.setEnabled(false);
            txtNilaiPT.setEnabled(false);
            txtThreshold.setEnabled(false);
        }
    }//GEN-LAST:event_jCheckBox1ActionPerformed

    private void buttonResetActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonResetActionPerformed
        // TODO add your handling code here:
        tablePreview.setModel(new javax.swing.table.DefaultTableModel(new Object[][] {}, new String[] { "NIS",
                "Nama", "JK", "UN", "Mean UN", "PT BINDO", "PT MTK", "PT BING", "PT IPA", "Mean PT", "Minat" }));
        initialization();
    }//GEN-LAST:event_buttonResetActionPerformed

    private void txtNumberOfKKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtNumberOfKKeyTyped
        // TODO add your handling code here:
        ControllerClassification controllerClassification = new ControllerClassification();
        controllerClassification.validasiNumberofNearest(evt, txtNumberOfK, labelPesanError);
    }//GEN-LAST:event_txtNumberOfKKeyTyped

    private void txtNumberOfKActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtNumberOfKActionPerformed
        // TODO add your handling code here:
        ControllerClassification controllerClassification = new ControllerClassification();
        controllerClassification.processMining(txtNumberOfK, tablePreview, labelPesanError, tableResult,
                labelSiswaIPA, labelSiswaIPS, labelKeterangan, jYearChooser1, jYearChooser2, jTabbedPane1);
        buttonSimpan.setEnabled(true);
        buttonReClass.setEnabled(true);
        jPanel5.setVisible(true);
    }//GEN-LAST:event_txtNumberOfKActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        // TODO add your handling code here:
        try {
            ControllerClassification controllerClassification = new ControllerClassification();
            controllerClassification.chooseFile(evt, txtFileDirectory, txtNumberOfK, labelJumlahData, buttonProses,
                    tablePreview);

        } catch (Exception e) {
            e.printStackTrace();
            JOptionPane.showMessageDialog(this, "Problem while upload file!", "Informasi Kesalahan Upload",
                    JOptionPane.WARNING_MESSAGE);
        }
    }//GEN-LAST:event_jButton1ActionPerformed

    private void buttonProsesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonProsesActionPerformed
        // TODO add your handling code here:

        if (jCheckBox1.isSelected()) {
            prosesManual();
        } else {
            ControllerClassification controllerClassification = new ControllerClassification();
            this.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
            controllerClassification.processMining(txtNumberOfK, tablePreview, labelPesanError, tableResult,
                    labelSiswaIPA, labelSiswaIPS, labelKeterangan, jYearChooser1, jYearChooser2, jTabbedPane1);
            this.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
        }
        buttonSimpan.setEnabled(true);
        buttonReClass.setEnabled(true);
        jPanel5.setVisible(true);
        //        jTabbedPane1.setSelectedIndex(1);
    }//GEN-LAST:event_buttonProsesActionPerformed

    private void txtNilaiUNKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtNilaiUNKeyReleased
        // TODO add your handling code here:
    }//GEN-LAST:event_txtNilaiUNKeyReleased

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton buttonProses;
    private javax.swing.JButton buttonReClass;
    private javax.swing.JButton buttonReset;
    private javax.swing.JButton buttonSimpan;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton5;
    private javax.swing.JCheckBox jCheckBox1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JTabbedPane jTabbedPane1;
    private com.toedter.calendar.JYearChooser jYearChooser1;
    private com.toedter.calendar.JYearChooser jYearChooser2;
    private javax.swing.JLabel labelJumlahData;
    private javax.swing.JLabel labelKeterangan;
    private javax.swing.JLabel labelPesanError;
    private javax.swing.JLabel labelPilihFile;
    private javax.swing.JLabel labelSiswaIPA;
    private javax.swing.JLabel labelSiswaIPS;
    private javax.swing.JTable tablePreview;
    private javax.swing.JTable tableResult;
    private javax.swing.JTextField txtFileDirectory;
    private javax.swing.JTextField txtNilaiPT;
    private javax.swing.JTextField txtNilaiUN;
    private javax.swing.JTextField txtNumberOfK;
    private javax.swing.JTextField txtThreshold;
    // End of variables declaration//GEN-END:variables

    private void initialization() {
        txtFileDirectory.setEditable(false);
        buttonProses.setEnabled(false);
        txtNumberOfK.setEnabled(false);
        labelPesanError.setText("");
        buttonSimpan.setEnabled(false);
        buttonReClass.setEnabled(false);
        jPanel5.setVisible(false);
        txtNilaiUN.setEnabled(false);
        txtNilaiPT.setEnabled(false);
        txtThreshold.setEnabled(false);

        jCheckBox1.setVisible(false);
        jLabel9.setVisible(false);
        jLabel10.setVisible(false);
        jLabel11.setVisible(false);
        jLabel12.setVisible(false);
        jLabel13.setVisible(false);
        txtNilaiUN.setVisible(false);
        txtNilaiPT.setVisible(false);
        txtThreshold.setVisible(false);
    }

    public void prosesManual() {
        int rowCountData = tablePreview.getRowCount();
        double[][] dataValue = getDataValue(rowCountData, tablePreview);
        String[] finalClass = hitungNilai(dataValue, rowCountData);
        tampilKeTabel(finalClass, rowCountData);

    }

    private double[][] getDataValue(int rowCountData, JTable tablePreview) {
        double[][] returnValue = new double[rowCountData][3];
        double transMinat = 0;
        for (int i = 0; i < rowCountData; i++) {
            if (tablePreview.getValueAt(i, 8).equals("IPA")) {
                transMinat = 1.0;
            } else if (tablePreview.getValueAt(i, 8).equals("IPS")) {
                transMinat = 0.0;
            }
            returnValue[i][0] = Double.parseDouble(tablePreview.getValueAt(i, 3).toString()) / 4;
            returnValue[i][1] = (Double.parseDouble(tablePreview.getValueAt(i, 4).toString())
                    + Double.parseDouble(tablePreview.getValueAt(i, 5).toString())
                    + Double.parseDouble(tablePreview.getValueAt(i, 6).toString())
                    + Double.parseDouble(tablePreview.getValueAt(i, 7).toString())) / 4;
            returnValue[i][2] = transMinat;
        }
        return returnValue;
    }

    private String[] hitungNilai(double[][] dataValue, int rowCountData) {
        //        DecimalFormat df = new DecimalFormat("##.00");
        String[] finalClass = new String[rowCountData];
        for (int i = 0; i < rowCountData; i++) {
            double a = dataValue[i][0] * (Double.parseDouble(txtNilaiUN.getText()) / 100);
            //            System.out.println("Nilai A = " + a);
            double b = dataValue[i][1] * (Double.parseDouble(txtNilaiPT.getText()) / 100);
            //            System.out.println("Nilai B = " + b);
            //            String c = df.format(a + b);
            double c = a + b;
            //            System.out.println("Nilai C = " + c);
            double d = dataValue[i][2];
            if (d == 1.0) {
                if (c >= Double.parseDouble(txtThreshold.getText())) {
                    System.out.println("Nilai C " + c);
                    System.out.println("Nilai Threshold " + Double.parseDouble(txtThreshold.getText()));
                    finalClass[i] = "IPA";
                } else {
                    finalClass[i] = "IPS";
                }
            } else {
                finalClass[i] = "IPS";
            }
        }
        return finalClass;
    }

    private void tampilKeTabel(String[] finalClass, int rowCountData) {
        DefaultTableModel tableModelResult = new DefaultTableModel();
        tableModelResult = (DefaultTableModel) tableResult.getModel();
        int jumlahSiswaIPA = 0;
        int jumlahSiswaIPS = 0;
        for (int i = 0; i < rowCountData; i++) {
            if (finalClass[i].equals("IPA")) {
                jumlahSiswaIPA = jumlahSiswaIPA + 1;
            } else if (finalClass[i].equalsIgnoreCase("IPS")) {
                jumlahSiswaIPS = jumlahSiswaIPS + 1;
            }

            String nis = tablePreview.getValueAt(i, 0).toString();
            String nama = tablePreview.getValueAt(i, 1).toString();
            String jenKel = tablePreview.getValueAt(i, 2).toString();
            String nilaiUN = tablePreview.getValueAt(i, 3).toString();
            String ptBindo = tablePreview.getValueAt(i, 4).toString();
            String ptMtk = tablePreview.getValueAt(i, 5).toString();
            String ptBing = tablePreview.getValueAt(i, 6).toString();
            String ptIpa = tablePreview.getValueAt(i, 7).toString();
            String minat = tablePreview.getValueAt(i, 8).toString();
            String jurusan = finalClass[i];
            Object[] resultData = { nis, nama, jenKel, nilaiUN, ptBindo, ptMtk, ptBing, ptIpa, minat, jurusan };
            tableModelResult.addRow(resultData);
        }
        jTabbedPane1.setSelectedIndex(1);
        labelKeterangan.setText("Hasil Klasifikasi Penjurusan Siswa Pada Tahun Ajaran " + jYearChooser1.getYear()
                + "/" + jYearChooser2.getYear() + ", dengan kriteria manual adalah sebagai berikut ");
        labelSiswaIPA.setText(jumlahSiswaIPA + "");
        labelSiswaIPS.setText(jumlahSiswaIPS + "");
        System.out.println("Jumlah IPA " + jumlahSiswaIPA);
        System.out.println("Jumlah IPS " + jumlahSiswaIPS);
    }

}