matres.MatResUI.java Source code

Java tutorial

Introduction

Here is the source code for matres.MatResUI.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 matres;

import java.io.InputStream;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JComboBox;
import weka.classifiers.bayes.NaiveBayes;
import weka.classifiers.trees.J48;
import weka.core.Attribute;
import weka.core.DenseInstance;
import weka.core.FastVector;
import weka.core.Instance;
import weka.core.Instances;

/**
 *
 * @author acer
 */
public class MatResUI extends javax.swing.JFrame {

    /**
     * Creates new form MatResUI
     */
    public MatResUI() {
        initComponents();
    }

    /**
     * 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() {

        jPanelDataPengamatan = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        m_cmbLO = new javax.swing.JComboBox();
        m_cmbSafety = new javax.swing.JComboBox();
        m_cmbEFC = new javax.swing.JComboBox();
        m_cmbSR = new javax.swing.JComboBox();
        m_cmbEC = new javax.swing.JComboBox();
        m_cmbCSSF = new javax.swing.JComboBox();
        m_btnReset = new javax.swing.JButton();
        m_btnClassify = new javax.swing.JButton();
        jPanelTree = new javax.swing.JPanel();
        jLabel7 = new javax.swing.JLabel();
        m_txtRisk = new javax.swing.JTextField();
        jPanelBayes = new javax.swing.JPanel();
        jLabel9 = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        jLabel11 = new javax.swing.JLabel();
        jLabel12 = new javax.swing.JLabel();
        jLabel13 = new javax.swing.JLabel();
        m_jBarRiskLow = new javax.swing.JProgressBar();
        m_jBarRiskModerate = new javax.swing.JProgressBar();
        m_jBarRiskHigh = new javax.swing.JProgressBar();
        m_jBarRiskExtreme = new javax.swing.JProgressBar();
        m_txtRiskNB = new javax.swing.JTextField();
        jMenuBar = new javax.swing.JMenuBar();
        mnuAplikasi = new javax.swing.JMenu();
        mnuKeluarAplikasi = new javax.swing.JMenuItem();
        mnuPerihal = new javax.swing.JMenu();
        mnuInfo = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Analisis Matriks Resiko");

        jPanelDataPengamatan.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        jPanelDataPengamatan.setToolTipText("");
        jPanelDataPengamatan.setName("pnlDataPengamatan"); // NOI18N

        jLabel1.setText("Likelihood of Occurrence");

        jLabel2.setText("Safety");

        jLabel3.setText("Extra Fuel Cost");

        jLabel4.setText("System Reliability");

        jLabel5.setText("Equipment Cost");

        jLabel6.setText("Customer Satisfaction / Social Factor");

        m_cmbLO.setModel(new javax.swing.DefaultComboBoxModel(
                new String[] { "-- none --", "> 10 in 1 year", "1 - 10 in 1 year", "1 in 1 year to 1 in 10 years",
                        "1 in 10 years to 1 in 100 years", "1 in more than 100 years" }));
        m_cmbLO.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                m_cmbLOActionPerformed(evt);
            }
        });

        m_cmbSafety.setModel(new javax.swing.DefaultComboBoxModel(
                new String[] { "-- none --", "near miss", "first aid injury, medical aid injury",
                        "lost time injury / temporary disability", "permanent disability", "fatality" }));
        m_cmbSafety.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                m_cmbSafetyActionPerformed(evt);
            }
        });

        m_cmbEFC.setModel(new javax.swing.DefaultComboBoxModel(
                new String[] { "-- none --", "< 100 million rupiah", "0,1 - 1 billion rupiah",
                        "1 - 10 billion rupiah", "10 - 100  billion rupiah", "> 100 billion rupiah" }));
        m_cmbEFC.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                m_cmbEFCActionPerformed(evt);
            }
        });

        m_cmbSR.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "-- none --", "< 100 MWh",
                "0,1 - 1 GWh", "1 - 10 GWh", "10 - 100 GWh", "> 100 GWh" }));
        m_cmbSR.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                m_cmbSRActionPerformed(evt);
            }
        });

        m_cmbEC.setModel(new javax.swing.DefaultComboBoxModel(
                new String[] { "-- none --", "< 50 million rupiah", "50 - 500 million rupiah",
                        "0,5 - 5 billion rupiah", "5 -50 billion rupiah", "> 50 billion rupiah" }));
        m_cmbEC.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                m_cmbECActionPerformed(evt);
            }
        });

        m_cmbCSSF.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "-- none --",
                "Complaint from the VIP customer", "Complaint from industrial customer", "Complaint from community",
                "Complaint from community that have potential riot", "High potential riot" }));
        m_cmbCSSF.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                m_cmbCSSFActionPerformed(evt);
            }
        });

        m_btnReset.setText("Reset");
        m_btnReset.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                m_btnResetActionPerformed(evt);
            }
        });

        m_btnClassify.setText("Classify");
        m_btnClassify.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                m_btnClassifyActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanelDataPengamatanLayout = new javax.swing.GroupLayout(jPanelDataPengamatan);
        jPanelDataPengamatan.setLayout(jPanelDataPengamatanLayout);
        jPanelDataPengamatanLayout.setHorizontalGroup(jPanelDataPengamatanLayout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanelDataPengamatanLayout.createSequentialGroup().addGap(14, 14, 14)
                        .addGroup(jPanelDataPengamatanLayout
                                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(jPanelDataPengamatanLayout.createSequentialGroup()
                                        .addComponent(m_btnClassify)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(m_btnReset).addGap(0, 0, Short.MAX_VALUE))
                                .addGroup(jPanelDataPengamatanLayout.createSequentialGroup()
                                        .addGroup(jPanelDataPengamatanLayout
                                                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                .addComponent(jLabel1, javax.swing.GroupLayout.Alignment.TRAILING)
                                                .addComponent(jLabel2, javax.swing.GroupLayout.Alignment.TRAILING)
                                                .addComponent(jLabel3, javax.swing.GroupLayout.Alignment.TRAILING)
                                                .addComponent(jLabel4, javax.swing.GroupLayout.Alignment.TRAILING)
                                                .addComponent(jLabel5, javax.swing.GroupLayout.Alignment.TRAILING)
                                                .addComponent(jLabel6, javax.swing.GroupLayout.Alignment.TRAILING))
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                        .addGroup(jPanelDataPengamatanLayout
                                                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                .addComponent(m_cmbLO, 0, javax.swing.GroupLayout.DEFAULT_SIZE,
                                                        Short.MAX_VALUE)
                                                .addComponent(m_cmbSafety, 0, javax.swing.GroupLayout.DEFAULT_SIZE,
                                                        Short.MAX_VALUE)
                                                .addComponent(m_cmbEFC, 0, javax.swing.GroupLayout.DEFAULT_SIZE,
                                                        Short.MAX_VALUE)
                                                .addComponent(m_cmbSR, 0, javax.swing.GroupLayout.DEFAULT_SIZE,
                                                        Short.MAX_VALUE)
                                                .addComponent(m_cmbEC, 0, javax.swing.GroupLayout.DEFAULT_SIZE,
                                                        Short.MAX_VALUE)
                                                .addComponent(m_cmbCSSF, 0, 688, Short.MAX_VALUE))))
                        .addContainerGap()));
        jPanelDataPengamatanLayout.setVerticalGroup(
                jPanelDataPengamatanLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(jPanelDataPengamatanLayout.createSequentialGroup().addGap(6, 6, 6)
                                .addGroup(jPanelDataPengamatanLayout
                                        .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                        .addComponent(m_cmbLO, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 21,
                                                javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(jPanelDataPengamatanLayout
                                        .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(m_cmbSafety, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(jPanelDataPengamatanLayout
                                        .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                        .addComponent(jLabel3, javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                        .addComponent(m_cmbEFC, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(jPanelDataPengamatanLayout
                                        .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addGroup(jPanelDataPengamatanLayout.createSequentialGroup()
                                                .addComponent(m_cmbSR, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addGap(0, 0, Short.MAX_VALUE))
                                        .addComponent(jLabel4, javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(jPanelDataPengamatanLayout
                                        .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                        .addComponent(m_cmbEC, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(jLabel5, javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED,
                                        javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addGroup(jPanelDataPengamatanLayout
                                        .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                        .addComponent(m_cmbCSSF, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(jLabel6, javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addGroup(jPanelDataPengamatanLayout
                                        .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                        .addComponent(m_btnReset).addComponent(m_btnClassify))
                                .addGap(21, 21, 21)));

        jPanelTree.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        jPanelTree.setToolTipText("Decision Tree");
        jPanelTree.setName("Decision Tree"); // NOI18N

        jLabel7.setText("Risk (Decision Tree)");

        m_txtRisk.setEditable(false);

        javax.swing.GroupLayout jPanelTreeLayout = new javax.swing.GroupLayout(jPanelTree);
        jPanelTree.setLayout(jPanelTreeLayout);
        jPanelTreeLayout
                .setHorizontalGroup(jPanelTreeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(jPanelTreeLayout.createSequentialGroup().addContainerGap().addComponent(jLabel7)
                                .addGap(29, 29, 29)
                                .addComponent(m_txtRisk, javax.swing.GroupLayout.PREFERRED_SIZE, 232,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)));
        jPanelTreeLayout.setVerticalGroup(jPanelTreeLayout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanelTreeLayout.createSequentialGroup().addContainerGap()
                        .addGroup(jPanelTreeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(m_txtRisk, javax.swing.GroupLayout.PREFERRED_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(jLabel7))
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)));

        jPanelBayes.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        jPanelBayes.setToolTipText("Naive Bayesian");

        jLabel9.setText("Risk (Naive Bayes)");

        jLabel10.setText("LOW");

        jLabel11.setText("MODERATE");

        jLabel12.setText("HIGH");

        jLabel13.setText("EXTREME");

        m_jBarRiskLow.setStringPainted(true);

        m_jBarRiskModerate.setStringPainted(true);

        m_jBarRiskHigh.setStringPainted(true);

        m_jBarRiskExtreme.setStringPainted(true);

        m_txtRiskNB.setEditable(false);

        javax.swing.GroupLayout jPanelBayesLayout = new javax.swing.GroupLayout(jPanelBayes);
        jPanelBayes.setLayout(jPanelBayesLayout);
        jPanelBayesLayout.setHorizontalGroup(jPanelBayesLayout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanelBayesLayout.createSequentialGroup().addContainerGap().addGroup(jPanelBayesLayout
                        .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(jPanelBayesLayout
                                .createSequentialGroup().addGap(10, 10, 10).addGroup(jPanelBayesLayout
                                        .createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                        .addGroup(jPanelBayesLayout.createSequentialGroup()
                                                .addGroup(
                                                        jPanelBayesLayout.createParallelGroup(
                                                                javax.swing.GroupLayout.Alignment.LEADING)
                                                                .addComponent(m_jBarRiskLow,
                                                                        javax.swing.GroupLayout.PREFERRED_SIZE,
                                                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                                                .addComponent(jLabel10))
                                                .addPreferredGap(
                                                        javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                                .addGroup(jPanelBayesLayout
                                                        .createParallelGroup(
                                                                javax.swing.GroupLayout.Alignment.LEADING)
                                                        .addComponent(jLabel11).addComponent(m_jBarRiskModerate,
                                                                javax.swing.GroupLayout.PREFERRED_SIZE,
                                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                                javax.swing.GroupLayout.PREFERRED_SIZE))
                                                .addPreferredGap(
                                                        javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                                .addGroup(jPanelBayesLayout
                                                        .createParallelGroup(
                                                                javax.swing.GroupLayout.Alignment.LEADING)
                                                        .addComponent(m_jBarRiskHigh,
                                                                javax.swing.GroupLayout.PREFERRED_SIZE,
                                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                                        .addComponent(jLabel12)))
                                        .addGroup(jPanelBayesLayout.createSequentialGroup()
                                                .addComponent(m_txtRiskNB, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                        232, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addGap(125, 125, 125)))
                                .addGroup(jPanelBayesLayout
                                        .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(jLabel13).addComponent(m_jBarRiskExtreme,
                                                javax.swing.GroupLayout.PREFERRED_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addContainerGap(258, Short.MAX_VALUE))
                        .addGroup(jPanelBayesLayout.createSequentialGroup().addComponent(jLabel9).addGap(0, 0,
                                Short.MAX_VALUE)))));
        jPanelBayesLayout.setVerticalGroup(jPanelBayesLayout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanelBayesLayout.createSequentialGroup().addContainerGap().addGroup(jPanelBayesLayout
                        .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addComponent(jLabel9)
                        .addComponent(m_txtRiskNB, javax.swing.GroupLayout.PREFERRED_SIZE,
                                javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanelBayesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jLabel10).addComponent(jLabel11).addComponent(jLabel12)
                                .addComponent(jLabel13))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanelBayesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(m_jBarRiskLow, javax.swing.GroupLayout.PREFERRED_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(m_jBarRiskModerate, javax.swing.GroupLayout.PREFERRED_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(m_jBarRiskHigh, javax.swing.GroupLayout.PREFERRED_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(m_jBarRiskExtreme, javax.swing.GroupLayout.PREFERRED_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)));

        mnuAplikasi.setText("Aplikasi");

        mnuKeluarAplikasi.setText("Keluar dari aplikasi");
        mnuKeluarAplikasi.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mnuKeluarAplikasiActionPerformed(evt);
            }
        });
        mnuAplikasi.add(mnuKeluarAplikasi);

        jMenuBar.add(mnuAplikasi);

        mnuPerihal.setText("Perihal");

        mnuInfo.setText("Informasi");
        mnuPerihal.add(mnuInfo);

        jMenuBar.add(mnuPerihal);

        setJMenuBar(jMenuBar);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup().addContainerGap()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(jPanelTree, javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(jPanelDataPengamatan, javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(jPanelBayes, javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addContainerGap()));
        layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup().addContainerGap()
                        .addComponent(jPanelDataPengamatan, javax.swing.GroupLayout.PREFERRED_SIZE,
                                javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jPanelTree, javax.swing.GroupLayout.PREFERRED_SIZE,
                                javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jPanelBayes, javax.swing.GroupLayout.PREFERRED_SIZE,
                                javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)));

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

    private void m_cmbCSSFActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_m_cmbCSSFActionPerformed
    }//GEN-LAST:event_m_cmbCSSFActionPerformed

    private void m_cmbLOActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_m_cmbLOActionPerformed
        /*
        JComboBox cb = (JComboBox) evt.getSource();
        String value = (String) cb.getItemAt(cb.getSelectedIndex());
        System.out.println(value);
        */
    }//GEN-LAST:event_m_cmbLOActionPerformed

    private void mnuKeluarAplikasiActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mnuKeluarAplikasiActionPerformed
        System.exit(0);
    }//GEN-LAST:event_mnuKeluarAplikasiActionPerformed

    private void m_cmbSafetyActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_m_cmbSafetyActionPerformed
    }//GEN-LAST:event_m_cmbSafetyActionPerformed

    private void m_cmbEFCActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_m_cmbEFCActionPerformed
    }//GEN-LAST:event_m_cmbEFCActionPerformed

    private void m_cmbSRActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_m_cmbSRActionPerformed
    }//GEN-LAST:event_m_cmbSRActionPerformed

    private void m_cmbECActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_m_cmbECActionPerformed
    }//GEN-LAST:event_m_cmbECActionPerformed

    private void m_btnResetActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_m_btnResetActionPerformed
        m_cmbLO.setSelectedIndex(0);
        m_cmbSafety.setSelectedIndex(0);
        m_cmbEFC.setSelectedIndex(0);
        m_cmbSR.setSelectedIndex(0);
        m_cmbEC.setSelectedIndex(0);
        m_cmbCSSF.setSelectedIndex(0);
        m_txtRisk.setText("");
        m_txtRiskNB.setText("");
        m_jBarRiskLow.setValue(0);
        m_jBarRiskLow.setString("0%");
        m_jBarRiskModerate.setValue(0);
        m_jBarRiskModerate.setString("0%");
        m_jBarRiskHigh.setValue(0);
        m_jBarRiskHigh.setString("0%");
        m_jBarRiskExtreme.setValue(0);
        m_jBarRiskExtreme.setString("0%");
    }//GEN-LAST:event_m_btnResetActionPerformed

    private void m_btnClassifyActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_m_btnClassifyActionPerformed
        doClassification();
    }//GEN-LAST:event_m_btnClassifyActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(MatResUI.class.getName()).log(java.util.logging.Level.SEVERE, null,
                    ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(MatResUI.class.getName()).log(java.util.logging.Level.SEVERE, null,
                    ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(MatResUI.class.getName()).log(java.util.logging.Level.SEVERE, null,
                    ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(MatResUI.class.getName()).log(java.util.logging.Level.SEVERE, null,
                    ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new MatResUI().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    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 jLabel9;
    private javax.swing.JMenuBar jMenuBar;
    private javax.swing.JPanel jPanelBayes;
    private javax.swing.JPanel jPanelDataPengamatan;
    private javax.swing.JPanel jPanelTree;
    private javax.swing.JButton m_btnClassify;
    private javax.swing.JButton m_btnReset;
    private javax.swing.JComboBox m_cmbCSSF;
    private javax.swing.JComboBox m_cmbEC;
    private javax.swing.JComboBox m_cmbEFC;
    private javax.swing.JComboBox m_cmbLO;
    private javax.swing.JComboBox m_cmbSR;
    private javax.swing.JComboBox m_cmbSafety;
    private javax.swing.JProgressBar m_jBarRiskExtreme;
    private javax.swing.JProgressBar m_jBarRiskHigh;
    private javax.swing.JProgressBar m_jBarRiskLow;
    private javax.swing.JProgressBar m_jBarRiskModerate;
    private javax.swing.JTextField m_txtRisk;
    private javax.swing.JTextField m_txtRiskNB;
    private javax.swing.JMenu mnuAplikasi;
    private javax.swing.JMenuItem mnuInfo;
    private javax.swing.JMenuItem mnuKeluarAplikasi;
    private javax.swing.JMenu mnuPerihal;
    // End of variables declaration//GEN-END:variables

    private void doClassification() {
        J48 m_treeResiko;
        J48 m_treeAksi;
        NaiveBayes m_nbResiko;
        NaiveBayes m_nbAksi;
        FastVector m_fvInstanceRisks;
        FastVector m_fvInstanceActions;

        InputStream isRiskTree = getClass().getResourceAsStream("data/ResikoTree.model");
        InputStream isRiskNB = getClass().getResourceAsStream("data/ResikoNB.model");
        InputStream isActionTree = getClass().getResourceAsStream("data/AksiTree.model");
        InputStream isActionNB = getClass().getResourceAsStream("data/AksiNB.model");

        m_treeResiko = new J48();
        m_treeAksi = new J48();
        m_nbResiko = new NaiveBayes();
        m_nbAksi = new NaiveBayes();
        try {
            //m_treeResiko = (J48) weka.core.SerializationHelper.read("ResikoTree.model");
            m_treeResiko = (J48) weka.core.SerializationHelper.read(isRiskTree);
            //m_nbResiko = (NaiveBayes) weka.core.SerializationHelper.read("ResikoNB.model");
            m_nbResiko = (NaiveBayes) weka.core.SerializationHelper.read(isRiskNB);
            //m_treeAksi = (J48) weka.core.SerializationHelper.read("AksiTree.model");
            m_treeAksi = (J48) weka.core.SerializationHelper.read(isActionTree);
            //m_nbAksi = (NaiveBayes) weka.core.SerializationHelper.read("AksiNB.model");
            m_nbAksi = (NaiveBayes) weka.core.SerializationHelper.read(isActionNB);
        } catch (Exception ex) {
            Logger.getLogger(MatResUI.class.getName()).log(Level.SEVERE, null, ex);
        }

        System.out.println("Setting up an Instance...");
        // Values for LIKELIHOOD OF OCCURRENCE
        FastVector fvLO = new FastVector(5);
        fvLO.addElement("> 10 in 1 year");
        fvLO.addElement("1 - 10 in 1 year");
        fvLO.addElement("1 in 1 year to 1 in 10 years");
        fvLO.addElement("1 in 10 years to 1 in 100 years");
        fvLO.addElement("1 in more than 100 years");
        // Values for SAFETY
        FastVector fvSafety = new FastVector(5);
        fvSafety.addElement("near miss");
        fvSafety.addElement("first aid injury, medical aid injury");
        fvSafety.addElement("lost time injury / temporary disability");
        fvSafety.addElement("permanent disability");
        fvSafety.addElement("fatality");
        // Values for EXTRA FUEL COST
        FastVector fvEFC = new FastVector(5);
        fvEFC.addElement("< 100 million rupiah");
        fvEFC.addElement("0,1 - 1 billion rupiah");
        fvEFC.addElement("1 - 10 billion rupiah");
        fvEFC.addElement("10 - 100  billion rupiah");
        fvEFC.addElement("> 100 billion rupiah");
        // Values for SYSTEM RELIABILITY
        FastVector fvSR = new FastVector(5);
        fvSR.addElement("< 100 MWh");
        fvSR.addElement("0,1 - 1 GWh");
        fvSR.addElement("1 - 10 GWh");
        fvSR.addElement("10 - 100 GWh");
        fvSR.addElement("> 100 GWh");
        // Values for EQUIPMENT COST
        FastVector fvEC = new FastVector(5);
        fvEC.addElement("< 50 million rupiah");
        fvEC.addElement("50 - 500 million rupiah");
        fvEC.addElement("0,5 - 5 billion rupiah");
        fvEC.addElement("5 -50 billion rupiah");
        fvEC.addElement("> 50 billion rupiah");
        // Values for CUSTOMER SATISFACTION SOCIAL FACTOR
        FastVector fvCSSF = new FastVector(5);
        fvCSSF.addElement("Complaint from the VIP customer");
        fvCSSF.addElement("Complaint from industrial customer");
        fvCSSF.addElement("Complaint from community");
        fvCSSF.addElement("Complaint from community that have potential riot");
        fvCSSF.addElement("High potential riot");
        // Values for RISK
        FastVector fvRisk = new FastVector(4);
        fvRisk.addElement("Low");
        fvRisk.addElement("Moderate");
        fvRisk.addElement("High");
        fvRisk.addElement("Extreme");
        // Values for ACTION
        FastVector fvAction = new FastVector(3);
        fvAction.addElement("Life Extension Program");
        fvAction.addElement("Repair/Refurbish");
        fvAction.addElement("Replace/Run to Fail + Investment");

        // Defining Attributes, including Class(es) Attributes
        Attribute attrLO = new Attribute("LO", fvLO);
        Attribute attrSafety = new Attribute("Safety", fvSafety);
        Attribute attrEFC = new Attribute("EFC", fvEFC);
        Attribute attrSR = new Attribute("SR", fvSR);
        Attribute attrEC = new Attribute("EC", fvEC);
        Attribute attrCSSF = new Attribute("CSSF", fvCSSF);
        Attribute attrRisk = new Attribute("Risk", fvRisk);
        Attribute attrAction = new Attribute("Action", fvAction);

        m_fvInstanceRisks = new FastVector(7);
        m_fvInstanceRisks.addElement(attrLO);
        m_fvInstanceRisks.addElement(attrSafety);
        m_fvInstanceRisks.addElement(attrEFC);
        m_fvInstanceRisks.addElement(attrSR);
        m_fvInstanceRisks.addElement(attrEC);
        m_fvInstanceRisks.addElement(attrCSSF);
        m_fvInstanceRisks.addElement(attrRisk);

        m_fvInstanceActions = new FastVector(7);
        m_fvInstanceActions.addElement(attrLO);
        m_fvInstanceActions.addElement(attrSafety);
        m_fvInstanceActions.addElement(attrEFC);
        m_fvInstanceActions.addElement(attrSR);
        m_fvInstanceActions.addElement(attrEC);
        m_fvInstanceActions.addElement(attrCSSF);
        m_fvInstanceActions.addElement(attrAction);

        Instances dataRisk = new Instances("A-Risk-instance-to-classify", m_fvInstanceRisks, 0);
        Instances dataAction = new Instances("An-Action-instance-to-classify", m_fvInstanceActions, 0);
        double[] riskValues = new double[dataRisk.numAttributes()];
        double[] actionValues = new double[dataRisk.numAttributes()];

        String strLO = (String) m_cmbLO.getSelectedItem();
        String strSafety = (String) m_cmbSafety.getSelectedItem();
        String strEFC = (String) m_cmbEFC.getSelectedItem();
        String strSR = (String) m_cmbSR.getSelectedItem();
        String strEC = (String) m_cmbEC.getSelectedItem();
        String strCSSF = (String) m_cmbCSSF.getSelectedItem();

        Instance instRisk = new DenseInstance(7);
        Instance instAction = new DenseInstance(7);

        if (strLO.equals("-- none --")) {
            instRisk.setMissing(0);
            instAction.setMissing(0);
        } else {
            instRisk.setValue((Attribute) m_fvInstanceRisks.elementAt(0), strLO);
            instAction.setValue((Attribute) m_fvInstanceActions.elementAt(0), strLO);
        }
        if (strSafety.equals("-- none --")) {
            instRisk.setMissing(1);
            instAction.setMissing(1);
        } else {
            instRisk.setValue((Attribute) m_fvInstanceRisks.elementAt(1), strSafety);
            instAction.setValue((Attribute) m_fvInstanceActions.elementAt(1), strSafety);
        }
        if (strEFC.equals("-- none --")) {
            instRisk.setMissing(2);
            instAction.setMissing(2);
        } else {
            instRisk.setValue((Attribute) m_fvInstanceRisks.elementAt(2), strEFC);
            instAction.setValue((Attribute) m_fvInstanceActions.elementAt(2), strEFC);
        }
        if (strSR.equals("-- none --")) {
            instRisk.setMissing(3);
            instAction.setMissing(3);
        } else {
            instRisk.setValue((Attribute) m_fvInstanceRisks.elementAt(3), strSR);
            instAction.setValue((Attribute) m_fvInstanceActions.elementAt(3), strSR);
        }
        if (strEC.equals("-- none --")) {
            instRisk.setMissing(4);
            instAction.setMissing(4);
        } else {
            instRisk.setValue((Attribute) m_fvInstanceRisks.elementAt(4), strEC);
            instAction.setValue((Attribute) m_fvInstanceActions.elementAt(4), strEC);
        }
        if (strCSSF.equals("-- none --")) {
            instRisk.setMissing(5);
            instAction.setMissing(5);
        } else {
            instAction.setValue((Attribute) m_fvInstanceActions.elementAt(5), strCSSF);
            instRisk.setValue((Attribute) m_fvInstanceRisks.elementAt(5), strCSSF);
        }
        instRisk.setMissing(6);
        instAction.setMissing(6);

        dataRisk.add(instRisk);
        instRisk.setDataset(dataRisk);
        dataRisk.setClassIndex(dataRisk.numAttributes() - 1);

        dataAction.add(instAction);
        instAction.setDataset(dataAction);
        dataAction.setClassIndex(dataAction.numAttributes() - 1);

        System.out.println("Instance Resiko: " + dataRisk.instance(0));
        System.out.println("\tNum Attributes : " + dataRisk.numAttributes());
        System.out.println("\tNum instances  : " + dataRisk.numInstances());
        System.out.println("Instance Action: " + dataAction.instance(0));
        System.out.println("\tNum Attributes : " + dataAction.numAttributes());
        System.out.println("\tNum instances  : " + dataAction.numInstances());

        int classIndexRisk = 0;
        int classIndexAction = 0;
        String strClassRisk = null;
        String strClassAction = null;

        try {
            //classIndexRisk = (int) m_treeResiko.classifyInstance(dataRisk.instance(0));
            classIndexRisk = (int) m_treeResiko.classifyInstance(instRisk);
            classIndexAction = (int) m_treeAksi.classifyInstance(instAction);
        } catch (Exception ex) {
            Logger.getLogger(MatResUI.class.getName()).log(Level.SEVERE, null, ex);
        }

        strClassRisk = (String) fvRisk.elementAt(classIndexRisk);
        strClassAction = (String) fvAction.elementAt(classIndexAction);
        System.out.println("[Risk  Class Index: " + classIndexRisk + " Class Label: " + strClassRisk + "]");
        System.out.println("[Action  Class Index: " + classIndexAction + " Class Label: " + strClassAction + "]");
        if (strClassRisk != null) {
            m_txtRisk.setText(strClassRisk);
        }

        double[] riskDist = null;
        double[] actionDist = null;
        try {
            riskDist = m_nbResiko.distributionForInstance(dataRisk.instance(0));
            actionDist = m_nbAksi.distributionForInstance(dataAction.instance(0));
            String strProb;
            // set up RISK progress bars
            m_jBarRiskLow.setValue((int) (100 * riskDist[0]));
            m_jBarRiskLow.setString(String.format("%6.3f%%", 100 * riskDist[0]));
            m_jBarRiskModerate.setValue((int) (100 * riskDist[1]));
            m_jBarRiskModerate.setString(String.format("%6.3f%%", 100 * riskDist[1]));
            m_jBarRiskHigh.setValue((int) (100 * riskDist[2]));
            m_jBarRiskHigh.setString(String.format("%6.3f%%", 100 * riskDist[2]));
            m_jBarRiskExtreme.setValue((int) (100 * riskDist[3]));
            m_jBarRiskExtreme.setString(String.format("%6.3f%%", 100 * riskDist[3]));
        } catch (Exception ex) {
            Logger.getLogger(MatResUI.class.getName()).log(Level.SEVERE, null, ex);
        }

        double predictedProb = 0.0;
        String predictedClass = "";

        // Loop over all the prediction labels in the distribution.
        for (int predictionDistributionIndex = 0; predictionDistributionIndex < riskDist.length; predictionDistributionIndex++) {
            // Get this distribution index's class label.
            String predictionDistributionIndexAsClassLabel = dataRisk.classAttribute()
                    .value(predictionDistributionIndex);
            int classIndex = dataRisk.classAttribute().indexOfValue(predictionDistributionIndexAsClassLabel);
            // Get the probability.
            double predictionProbability = riskDist[predictionDistributionIndex];

            if (predictionProbability > predictedProb) {
                predictedProb = predictionProbability;
                predictedClass = predictionDistributionIndexAsClassLabel;
            }

            System.out.printf("[%2d %10s : %6.3f]", classIndex, predictionDistributionIndexAsClassLabel,
                    predictionProbability);
        }
        m_txtRiskNB.setText(predictedClass);
    }
}