/*
 * 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 visual;

import java.awt.Component;
import java.util.*;
import javax.swing.*;
import logica.logica;

/**
 *
 * @author LuisIván
 */
public class Prototipo extends javax.swing.JFrame {

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

        myPanel = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        Cifra1Check = new javax.swing.JCheckBox();
        Cifra2Check = new javax.swing.JCheckBox();
        Cifra3Check = new javax.swing.JCheckBox();
        fireButton = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        TableArea = new javax.swing.JTextArea();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setSize(new java.awt.Dimension(800, 800));

        myPanel.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));

        jLabel1.setFont(new java.awt.Font("Miriam Fixed", 0, 48)); // NOI18N
        jLabel1.setText("Multiplicaciones");

        Cifra1Check.setText("Multiplicación de 1 cifra");
        Cifra1Check.setName(""); // NOI18N
        Cifra1Check.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                Cifra1CheckActionPerformed(evt);
            }
        });

        Cifra2Check.setText("Multiplicación de 2 cifras");
        Cifra2Check.setActionCommand("Multiplicación de 2 términos");
        Cifra2Check.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                Cifra2CheckActionPerformed(evt);
            }
        });

        Cifra3Check.setText("Multiplicación de 3 cifras");

        fireButton.setText("Fire!");
        fireButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                fireButtonActionPerformed(evt);
            }
        });

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

        javax.swing.GroupLayout myPanelLayout = new javax.swing.GroupLayout(myPanel);
        myPanel.setLayout(myPanelLayout);
        myPanelLayout.setHorizontalGroup(
            myPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, myPanelLayout.createSequentialGroup()
                .addGap(22, 22, 22)
                .addComponent(jScrollPane1)
                .addGroup(myPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(myPanelLayout.createSequentialGroup()
                        .addGap(92, 92, 92)
                        .addComponent(fireButton))
                    .addGroup(myPanelLayout.createSequentialGroup()
                        .addGap(56, 56, 56)
                        .addGroup(myPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(Cifra1Check)
                            .addComponent(Cifra2Check)
                            .addComponent(Cifra3Check))))
                .addGap(92, 92, 92))
            .addGroup(myPanelLayout.createSequentialGroup()
                .addGap(90, 90, 90)
                .addComponent(jLabel1)
                .addContainerGap(92, Short.MAX_VALUE))
        );
        myPanelLayout.setVerticalGroup(
            myPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(myPanelLayout.createSequentialGroup()
                .addGroup(myPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(myPanelLayout.createSequentialGroup()
                        .addGap(18, 18, 18)
                        .addComponent(jLabel1)
                        .addGap(94, 94, 94)
                        .addComponent(Cifra1Check)
                        .addGap(18, 18, 18)
                        .addComponent(Cifra2Check)
                        .addGap(30, 30, 30)
                        .addComponent(Cifra3Check))
                    .addGroup(myPanelLayout.createSequentialGroup()
                        .addGap(116, 116, 116)
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 185, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 109, Short.MAX_VALUE)
                .addComponent(fireButton)
                .addGap(20, 20, 20))
        );

        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()
                .addComponent(myPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(myPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );

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

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

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

    private void fireButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_fireButtonActionPerformed
            double table = 0; double []adivinado = new double[11];
            String st[] = new String[11]; int r=0;
            if(Cifra1Check.isSelected() && Cifra2Check.isSelected()){
                JOptionPane.showMessageDialog(rootPane, "No puedes seleccionar 2 operaciones al mismo tiempo");
            }
            else if(Cifra1Check.isSelected() && Cifra3Check.isSelected()){
                JOptionPane.showMessageDialog(rootPane, "No puedes seleccionar 2 operaciones al mismo tiempo");
            }
            else if (Cifra2Check.isSelected() && Cifra3Check.isSelected()){
                JOptionPane.showMessageDialog(rootPane, "No puedes seleccionar 2 operaciones al mismo tiempo");
            }
            else if(Cifra1Check.isSelected()){
                table = Double.parseDouble(JOptionPane.showInputDialog("Tabla a practicar: "));
                logica ln = new logica(table);
                for (int i = 0; i < st.length; i++) {
                    do {
                        if(adivinado[i]!=table*i){
                            r++;
                            adivinado[i] = Double.parseDouble(JOptionPane.showInputDialog("El resultado de: "+table+" x "+i+" = "));
                            st[i] = (table+ " x " + i + " = "+adivinado[i]);
                            TableArea.append(st[i]);
                            TableArea.append("\n");
                            ln.setDato(adivinado[i]);
                        }
                    } while (adivinado[i]!= table * i);
                }
                JOptionPane.showMessageDialog(rootPane,"**Número de intentos = " + (r)+"**Te equivocaste en: "+(r-10));
                ln.makeTableWithOne(table, adivinado);
                
            }
    }//GEN-LAST:event_fireButtonActionPerformed

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

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JCheckBox Cifra1Check;
    private javax.swing.JCheckBox Cifra2Check;
    private javax.swing.JCheckBox Cifra3Check;
    private javax.swing.JTextArea TableArea;
    private javax.swing.JButton fireButton;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JPanel myPanel;
    // End of variables declaration//GEN-END:variables
}
