c4.pkg5crossv.Preview.java Source code

Java tutorial

Introduction

Here is the source code for c4.pkg5crossv.Preview.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 c4.pkg5crossv;

import java.io.IOException;
import java.util.Arrays;
import javax.swing.table.DefaultTableModel;
import weka.core.Instances;
import weka.gui.arffviewer.ArffSortedTableModel;

/**
 *
 * @author si
 */
public class Preview extends javax.swing.JFrame {

    /**
     * method to write arff data into s.o.p.
     * @throws IOException 
     */

    public static void showData() throws IOException {

        String source = MainWindow.browsedFileLabel.getText();
        Instances data = DataLoad.loadData(source.replace("\\", "/"));
        data.setClassIndex(data.numAttributes() - 1);
        String field = "";
        for (int i = 0; i < data.numAttributes(); i++) {
            // Print the current attribute.
            System.out.print(data.attribute(i).name() + ": ");
            previewTextArea.append("\n" + data.attribute(i).name() + ": ");
            // Print the values associated with the current attribute.
            double[] values = data.attributeToDoubleArray(i);

            System.out.println(Arrays.toString(values));
            previewTextArea.append(Arrays.toString(values));
        }

    }

    /**
     * Creates new form Preview
     */
    public Preview() {
        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() {

        jScrollPane1 = new javax.swing.JScrollPane();
        previewTextArea = new javax.swing.JTextArea();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        previewTextArea.setColumns(20);
        previewTextArea.setRows(5);
        jScrollPane1.setViewportView(previewTextArea);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 451, Short.MAX_VALUE));
        layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 322, Short.MAX_VALUE));

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

    /**
     * @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(Preview.class.getName()).log(java.util.logging.Level.SEVERE, null,
                    ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(Preview.class.getName()).log(java.util.logging.Level.SEVERE, null,
                    ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(Preview.class.getName()).log(java.util.logging.Level.SEVERE, null,
                    ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(Preview.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 Preview().setVisible(true);

            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JScrollPane jScrollPane1;
    public static javax.swing.JTextArea previewTextArea;
    // End of variables declaration//GEN-END:variables
}