/*
 * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
 * Click nbfs://nbhost/SystemFileSystem/Templates/GUIForms/JFrame.java to edit this template
 */
package com.mycompany.linkedlistdemo;
import java.util.Locale;
import javax.swing.*;

/**
 *
 * @author zulfi
 */
public class LLJFrame extends javax.swing.JFrame {
    LinkedList obj;

    /**
     * Creates new form LLJFrame
     */
    public LLJFrame() {
        initComponents();
        obj =new LinkedList() ;
    }

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

        jTF1 = new javax.swing.JTextField();
        jAddBtn = new javax.swing.JButton();
        jInsertBtn = new javax.swing.JButton();
        jEditBtn = new javax.swing.JButton();
        jDispBtn = new javax.swing.JButton();
        jTF2 = new javax.swing.JTextField();
        jDelBtn = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jTF1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTF1ActionPerformed(evt);
            }
        });

        jAddBtn.setText("ADD");
        jAddBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jAddBtnActionPerformed(evt);
            }
        });

        jInsertBtn.setText("INSERT");

        jEditBtn.setText("EDIT");

        jDispBtn.setText("DISPLAY");
        jDispBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jDispBtnActionPerformed(evt);
            }
        });

        jDelBtn.setText("DELETE");
        jDelBtn.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                jDelBtnStateChanged(evt);
            }
        });
        jDelBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jDelBtnActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(213, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jDelBtn)
                    .addComponent(jDispBtn)
                    .addComponent(jAddBtn)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jInsertBtn)
                            .addComponent(jEditBtn))
                        .addGap(42, 42, 42)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jTF2, javax.swing.GroupLayout.PREFERRED_SIZE, 98, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jTF1, javax.swing.GroupLayout.PREFERRED_SIZE, 106, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addGap(263, 263, 263))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(25, 25, 25)
                .addComponent(jAddBtn)
                .addGap(18, 18, 18)
                .addComponent(jDelBtn)
                .addGap(29, 29, 29)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jInsertBtn)
                    .addComponent(jTF1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(38, 38, 38)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jEditBtn)
                    .addComponent(jTF2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(38, 38, 38)
                .addComponent(jDispBtn)
                .addContainerGap(156, Short.MAX_VALUE))
        );

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

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

    private void jAddBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jAddBtnActionPerformed
        // TODO add your handling code here:
        
        int data = Integer.parseInt(jTF1.getText());
        obj.add(data);
    }//GEN-LAST:event_jAddBtnActionPerformed

    private void jDispBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jDispBtnActionPerformed
        // TODO add your handling code here:
       // LinkedList obj =new LinkedList() ;
       
        String str = obj.printList();
        JOptionPane.showMessageDialog(null, "str= "+str);
        jTF2.setText(str);
    }//GEN-LAST:event_jDispBtnActionPerformed

    private boolean jDelBtnActionPerformed(java.awt.event.ActionEvent evt) {                                     
        // TODO add your handling code here:
        JOptionPane.showMessageDialog(null, "Inside Delete Btn");
        String str = "";
        try{
        str = jTF1.getText().trim();
        }catch(java.lang.NumberFormatException e){
            e.printStackTrace();
            JOptionPane.showMessageDialog(null, "Inside Exception Handler");
        }
        int len = str.length();
        JOptionPane.showMessageDialog(null, "len="+ len+"str=" +str);
        if(str == ""){//WHY THIS LINE NOT EXECUTED
            JOptionPane.showMessageDialog(null, "No Data to Delete");
            return false;
        }
        System.out.println("TESTING TESTING TESTING");
        int data = Integer.parseInt(jTF1.getText().trim());//NUMBER FORMAT Exception
       //Integer.parseInt(quantityString.trim())
        System.out.println("data = "+data);
        obj.delete(data);
        return true;
    }         
    private boolean jDelBtnStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_jDelBtnStateChanged
        // TODO add your handling code here:
        return true;
    }//GEN-LAST:event_jDelBtnStateChanged

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

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jAddBtn;
    private javax.swing.JButton jDelBtn;
    private javax.swing.JButton jDispBtn;
    private javax.swing.JButton jEditBtn;
    private javax.swing.JButton jInsertBtn;
    private javax.swing.JTextField jTF1;
    private javax.swing.JTextField jTF2;
    // End of variables declaration//GEN-END:variables
}
