GUI.pantalla1.java Source code

Java tutorial

Introduction

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

import Node.Lista;
import java.awt.BorderLayout;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JFrame;
import logic.generador;
import org.jfree.chart.ChartFactory;
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 ellioth
 */
public class pantalla1 extends JFrame {
    private PanelDeGrafica graf;
    private Lista list;
    private DefaultCategoryDataset cuadro;
    private generador rand;

    public pantalla1() throws IOException {
        rand = new generador();
        list = new Lista();
        graf = new PanelDeGrafica();
        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.
     * @param metodo
     * @return 
     */
    @SuppressWarnings("unchecked")

    /*public Lista getLista(){
    return list;
    }*/
    public Lista getLista() {
        return list;
    }

    public int getCantidadDat() {
        return Integer.parseInt(CantMax.getText());
    }

    public int getCantRecur() {
        return Integer.parseInt(CantRecur.getText());
    }

    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel2 = new javax.swing.JPanel();
        CalcInt = new javax.swing.JButton();
        CalcStrin = new javax.swing.JButton();
        jLabel2 = new javax.swing.JLabel();
        PanelGrafico = new javax.swing.JPanel();
        InseA = new javax.swing.JButton();
        quiA = new javax.swing.JButton();
        merA = new javax.swing.JButton();
        burbA = new javax.swing.JButton();
        radA = new javax.swing.JButton();
        burbL = new javax.swing.JButton();
        merL = new javax.swing.JButton();
        selcA = new javax.swing.JButton();
        quiL = new javax.swing.JButton();
        selL = new javax.swing.JButton();
        radL = new javax.swing.JButton();
        insL = new javax.swing.JButton();
        CantMax = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        MemoMet = new javax.swing.JButton();
        jLabel3 = new javax.swing.JLabel();
        CantRecur = new javax.swing.JTextField();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setBackground(new java.awt.Color(53, 212, 192));

        jPanel2.setLayout(new java.awt.BorderLayout());

        CalcInt.setText("Calcular con Ints");
        CalcInt.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                CalcIntActionPerformed(evt);
            }
        });

        CalcStrin.setText("Calcular con Strings");
        CalcStrin.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                CalcStrinActionPerformed(evt);
            }
        });

        jLabel2.setFont(new java.awt.Font("Kokonor", 0, 18)); // NOI18N
        jLabel2.setText("METODOS DE ORDENAMIENTOS ");
        jLabel2.setToolTipText("");

        PanelGrafico.setBackground(new java.awt.Color(204, 0, 255));
        PanelGrafico.setForeground(new java.awt.Color(204, 51, 255));
        PanelGrafico.setLayout(new java.awt.BorderLayout());

        InseA.setText("Insert-arreglo");
        InseA.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                InseAActionPerformed(evt);
            }
        });

        quiA.setText("Quick-arreglo");
        quiA.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                quiAActionPerformed(evt);
            }
        });

        merA.setText("Merge-arreglo");
        merA.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                merAActionPerformed(evt);
            }
        });

        burbA.setText("Burbuja-arreglo");
        burbA.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                burbAActionPerformed(evt);
            }
        });

        radA.setText("Raddix-arreglo");
        radA.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                radAActionPerformed(evt);
            }
        });

        burbL.setText("Burbuja-lista");
        burbL.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                burbLActionPerformed(evt);
            }
        });

        merL.setText("Merge-lista");
        merL.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                merLActionPerformed(evt);
            }
        });

        selcA.setText("Selection-arreglo");
        selcA.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                selcAActionPerformed(evt);
            }
        });

        quiL.setText("Quick-lista");
        quiL.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                quiLActionPerformed(evt);
            }
        });

        selL.setText("Selection-lista");
        selL.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                selLActionPerformed(evt);
            }
        });

        radL.setText("Raddix-lista");
        radL.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                radLActionPerformed(evt);
            }
        });

        insL.setText("Insert-lista");
        insL.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                insLActionPerformed(evt);
            }
        });

        CantMax.setText("1000");
        CantMax.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                CantMaxActionPerformed(evt);
            }
        });

        jLabel1.setFont(new java.awt.Font("Kokonor", 0, 14)); // NOI18N
        jLabel1.setText("Cantidad de datos");

        MemoMet.setText("Limpiar memoria de metodos");
        MemoMet.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                MemoMetActionPerformed(evt);
            }
        });

        jLabel3.setFont(new java.awt.Font("Kokonor", 0, 14)); // NOI18N
        jLabel3.setText("Cantidad de recursiones");

        CantRecur.setText("30");
        CantRecur.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                CantRecurActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE,
                        Short.MAX_VALUE)
                .addGroup(layout.createSequentialGroup().addGroup(layout
                        .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(layout.createSequentialGroup().addGroup(layout
                                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(layout.createSequentialGroup().addGap(21, 21, 21).addGroup(layout
                                        .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(burbA)
                                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout
                                                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                .addComponent(radA).addComponent(quiL))
                                        .addComponent(jLabel1, javax.swing.GroupLayout.Alignment.TRAILING,
                                                javax.swing.GroupLayout.PREFERRED_SIZE, 116,
                                                javax.swing.GroupLayout.PREFERRED_SIZE))
                                        .addGap(18, 18, 18)
                                        .addGroup(layout
                                                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING,
                                                        false)
                                                .addGroup(layout.createSequentialGroup().addGroup(layout
                                                        .createParallelGroup(
                                                                javax.swing.GroupLayout.Alignment.LEADING, false)
                                                        .addGroup(layout.createSequentialGroup().addComponent(merA)
                                                                .addGap(18, 18, 18).addComponent(quiA))
                                                        .addGroup(layout.createSequentialGroup()
                                                                .addGroup(layout.createParallelGroup(
                                                                        javax.swing.GroupLayout.Alignment.LEADING)
                                                                        .addComponent(selcA).addComponent(insL))
                                                                .addPreferredGap(
                                                                        javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                                .addGroup(layout.createParallelGroup(
                                                                        javax.swing.GroupLayout.Alignment.LEADING)
                                                                        .addComponent(radL).addComponent(burbL))))
                                                        .addGap(29, 29, 29)
                                                        .addGroup(layout
                                                                .createParallelGroup(
                                                                        javax.swing.GroupLayout.Alignment.LEADING)
                                                                .addComponent(merL).addComponent(InseA)
                                                                .addComponent(selL)))
                                                .addGroup(layout.createSequentialGroup()
                                                        .addComponent(CantMax,
                                                                javax.swing.GroupLayout.PREFERRED_SIZE, 69,
                                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                                        .addPreferredGap(
                                                                javax.swing.LayoutStyle.ComponentPlacement.RELATED,
                                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                                Short.MAX_VALUE)
                                                        .addComponent(jLabel3,
                                                                javax.swing.GroupLayout.PREFERRED_SIZE, 146,
                                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                                        .addGap(28, 28, 28)
                                                        .addComponent(CantRecur,
                                                                javax.swing.GroupLayout.PREFERRED_SIZE, 53,
                                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                                        .addGap(115, 115, 115))))
                                .addGroup(layout.createSequentialGroup().addGap(234, 234, 234).addComponent(jLabel2,
                                        javax.swing.GroupLayout.PREFERRED_SIZE, 327,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(MemoMet)
                                        .addGroup(layout
                                                .createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING,
                                                        false)
                                                .addComponent(CalcInt, javax.swing.GroupLayout.Alignment.LEADING,
                                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                                        javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                                .addComponent(CalcStrin, javax.swing.GroupLayout.Alignment.LEADING,
                                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                                        javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
                        .addGroup(layout.createSequentialGroup().addContainerGap().addComponent(PanelGrafico,
                                javax.swing.GroupLayout.PREFERRED_SIZE, 813,
                                javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addContainerGap(26, Short.MAX_VALUE)));
        layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup().addContainerGap()
                        .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 36,
                                javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(10, 10, 10)
                        .addGroup(layout
                                .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE).addComponent(InseA)
                                .addComponent(quiA).addComponent(merA).addComponent(burbA).addComponent(CalcStrin))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(radA).addComponent(selcA).addComponent(burbL).addComponent(merL)
                                .addComponent(CalcInt))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(insL).addComponent(quiL).addComponent(radL).addComponent(selL))
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING,
                                        layout.createSequentialGroup()
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED,
                                                        javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                                .addComponent(MemoMet).addGap(46, 46, 46))
                                .addGroup(layout.createSequentialGroup().addGap(18, 18, 18)
                                        .addGroup(layout
                                                .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                                .addComponent(CantMax, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addComponent(jLabel1).addComponent(jLabel3).addComponent(CantRecur,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE,
                                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE))
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED,
                                                javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                        .addComponent(PanelGrafico, javax.swing.GroupLayout.DEFAULT_SIZE, 367, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addComponent(jPanel2,
                                javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE,
                                javax.swing.GroupLayout.PREFERRED_SIZE)));

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

    private void CalcStrinActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_CalcStrinActionPerformed
        // TODO add your handling code here:
        cuadro = new DefaultCategoryDataset();
        try {
            graf.ListaDeMetodos(list);
            graf.metodosOrdA(cuadro, rand.generadorArrString(getCantidadDat()));
            graf.metodosOrdL(cuadro, rand.generadorListString(getCantidadDat()));
        } catch (IOException ex) {
            Logger.getLogger(pantalla1.class.getName()).log(Level.SEVERE, null, ex);
            System.out.println("error en ordenamiento con listas y arreglos de Strings");
        }
        JFreeChart grafica = ChartFactory.createBarChart("Metodos de ordenamiento con Strings", "promedio",
                "Tiempo de duracion", cuadro, PlotOrientation.VERTICAL, true, true, false);
        CategoryPlot grfic = grafica.getCategoryPlot();
        ChartPanel barras = new ChartPanel(grafica);
        PanelGrafico.removeAll();
        PanelGrafico.add(barras, BorderLayout.CENTER);
        PanelGrafico.validate();
    }//GEN-LAST:event_CalcStrinActionPerformed

    private void CalcIntActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_CalcIntActionPerformed
        // TODO add your handling code here:
        cuadro = new DefaultCategoryDataset();
        try {
            graf.ListaDeMetodos(list);
            graf.metodosOrdA(cuadro, rand.generadorArrInt(getCantidadDat()));
            graf.metodosOrdL(cuadro, rand.generadorListInt(getCantidadDat()));
        } catch (IOException ex) {
            Logger.getLogger(pantalla1.class.getName()).log(Level.SEVERE, null, ex);
            System.out.println("error en ordenamiento con listas y arreglos de ints");
        }
        JFreeChart grafica = ChartFactory.createBarChart("Metodos de ordenamiento con Ints", "promedio",
                "Tiempo de duracion", cuadro, PlotOrientation.VERTICAL, true, true, false);
        CategoryPlot grfic = grafica.getCategoryPlot();
        ChartPanel barras = new ChartPanel(grafica);
        PanelGrafico.removeAll();
        PanelGrafico.add(barras, BorderLayout.CENTER);
        PanelGrafico.validate();

    }//GEN-LAST:event_CalcIntActionPerformed

    private void burbAActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_burbAActionPerformed
        // TODO add your handling code here:
        list.insertHead("burbuja-array");
    }//GEN-LAST:event_burbAActionPerformed

    private void merAActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_merAActionPerformed
        // TODO add your handling code here:
        list.insertHead("merge-array");
    }//GEN-LAST:event_merAActionPerformed

    private void quiAActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_quiAActionPerformed
        // TODO add your handling code here:
        list.insertHead("quick-array");
    }//GEN-LAST:event_quiAActionPerformed

    private void InseAActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_InseAActionPerformed
        // TODO add your handling code here:
        list.insertHead("insert-array");
    }//GEN-LAST:event_InseAActionPerformed

    private void radAActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_radAActionPerformed
        // TODO add your handling code here:
        list.insertHead("raddix-array");
    }//GEN-LAST:event_radAActionPerformed

    private void selcAActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_selcAActionPerformed
        // TODO add your handling code here:
        list.insertHead("selection-array");
    }//GEN-LAST:event_selcAActionPerformed

    private void burbLActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_burbLActionPerformed
        // TODO add your handling code here:
        list.insertHead("burbuja-lista");
    }//GEN-LAST:event_burbLActionPerformed

    private void merLActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_merLActionPerformed
        // TODO add your handling code here:
        list.insertHead("merge-lista");
    }//GEN-LAST:event_merLActionPerformed

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

        list.insertHead("quick-lista");
    }//GEN-LAST:event_quiLActionPerformed

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

        list.insertHead("insert-lista");
    }//GEN-LAST:event_insLActionPerformed

    private void radLActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_radLActionPerformed
        // TODO add your handling code here:
        list.insertHead("raddix-lista");
    }//GEN-LAST:event_radLActionPerformed

    private void selLActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_selLActionPerformed
        // TODO add your handling code here:
        list.insertHead("selection-lista");
    }//GEN-LAST:event_selLActionPerformed

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

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

    private void MemoMetActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_MemoMetActionPerformed
        // TODO add your handling code here:
        list = new Lista();
    }//GEN-LAST:event_MemoMetActionPerformed

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

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                try {
                    new pantalla1().setVisible(true);
                } catch (IOException ex) {
                    Logger.getLogger(pantalla1.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton CalcInt;
    private javax.swing.JButton CalcStrin;
    private javax.swing.JTextField CantMax;
    private javax.swing.JTextField CantRecur;
    private javax.swing.JButton InseA;
    private javax.swing.JButton MemoMet;
    private javax.swing.JPanel PanelGrafico;
    private javax.swing.JButton burbA;
    private javax.swing.JButton burbL;
    private javax.swing.JButton insL;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JButton merA;
    private javax.swing.JButton merL;
    private javax.swing.JButton quiA;
    private javax.swing.JButton quiL;
    private javax.swing.JButton radA;
    private javax.swing.JButton radL;
    private javax.swing.JButton selL;
    private javax.swing.JButton selcA;
    // End of variables declaration//GEN-END:variables

}