Package Views

Source Code of Views.panelNewAuthor

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

import Helpers.DbHelper;
import Models.Pojo.Author;
import Models.AuthorModel;
import java.sql.Connection;
import javax.swing.JOptionPane;

/**
*
* @author Tejas
*/
public class panelNewAuthor extends javax.swing.JPanel {

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

        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        txtAuthorFullName = new javax.swing.JTextField();
        txtAuthorLocation = new javax.swing.JTextField();
        txtAuthorAge = new javax.swing.JTextField();
        txtAuthorDetails = new javax.swing.JTextField();
        btnSubmitAuthor = new javax.swing.JButton();

        jLabel1.setFont(new java.awt.Font("Verdana", 0, 13)); // NOI18N
        jLabel1.setText("Full Name");

        jLabel2.setFont(new java.awt.Font("Verdana", 0, 13)); // NOI18N
        jLabel2.setText("Location");

        jLabel3.setFont(new java.awt.Font("Verdana", 0, 13)); // NOI18N
        jLabel3.setText("Age");

        jLabel5.setFont(new java.awt.Font("Verdana", 0, 13)); // NOI18N
        jLabel5.setText("Details");

        jLabel6.setFont(new java.awt.Font("Verdana", 1, 18)); // NOI18N
        jLabel6.setForeground(new java.awt.Color(66, 95, 211));
        jLabel6.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel6.setText("New Author");

        txtAuthorFullName.setColumns(15);
        txtAuthorFullName.setFont(new java.awt.Font("Verdana", 0, 13)); // NOI18N

        txtAuthorLocation.setColumns(15);
        txtAuthorLocation.setFont(new java.awt.Font("Verdana", 0, 13)); // NOI18N

        txtAuthorAge.setColumns(15);
        txtAuthorAge.setFont(new java.awt.Font("Verdana", 0, 13)); // NOI18N
        txtAuthorAge.setToolTipText("In Digit ex.24");

        txtAuthorDetails.setColumns(15);
        txtAuthorDetails.setFont(new java.awt.Font("Verdana", 0, 13)); // NOI18N

        btnSubmitAuthor.setFont(new java.awt.Font("Verdana", 0, 13)); // NOI18N
        btnSubmitAuthor.setText("Submit");
        btnSubmitAuthor.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSubmitAuthorActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(100, 100, 100)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel6, javax.swing.GroupLayout.PREFERRED_SIZE, 367, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel1)
                            .addComponent(jLabel2)
                            .addComponent(jLabel3)
                            .addComponent(jLabel5))
                        .addGap(121, 121, 121)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(txtAuthorDetails)
                            .addComponent(txtAuthorAge)
                            .addComponent(txtAuthorLocation)
                            .addComponent(txtAuthorFullName)
                            .addComponent(btnSubmitAuthor, javax.swing.GroupLayout.PREFERRED_SIZE, 100, 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()
                .addGap(50, 50, 50)
                .addComponent(jLabel6)
                .addGap(40, 40, 40)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(txtAuthorFullName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(txtAuthorLocation, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(txtAuthorAge, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5)
                    .addComponent(txtAuthorDetails, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(37, 37, 37)
                .addComponent(btnSubmitAuthor)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void btnSubmitAuthorActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSubmitAuthorActionPerformed
        //Insert New author  To the db
        String full_name    = txtAuthorFullName.getText();
        String location     = txtAuthorLocation.getText();
        int age             = Integer.parseInt(txtAuthorAge.getText());
        String details      = txtAuthorDetails.getText();

        Author author = new Author();
        AuthorModel authorModel = new AuthorModel();

        author.setFull_name(full_name);
        author.setLocation(location);
        author.setAge(age);
        author.setDetails(details);
       
        int flag = authorModel.save(author);
        if(flag == 1)
        {
            JOptionPane.showMessageDialog(null, "Author added !", "Message", JOptionPane.INFORMATION_MESSAGE);
            clearAllTextFields();
        }
        else{
            JOptionPane.showMessageDialog(null, "Failed to add author!", "Message", JOptionPane.ERROR_MESSAGE);
        }

    }//GEN-LAST:event_btnSubmitAuthorActionPerformed
   
    private void clearAllTextFields(){
        txtAuthorAge.setText(null);
        txtAuthorDetails.setText(null);
        txtAuthorFullName.setText(null);
        txtAuthorLocation.setText(null);       
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnSubmitAuthor;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JTextField txtAuthorAge;
    private javax.swing.JTextField txtAuthorDetails;
    private javax.swing.JTextField txtAuthorFullName;
    private javax.swing.JTextField txtAuthorLocation;
    // End of variables declaration//GEN-END:variables
}
TOP

Related Classes of Views.panelNewAuthor

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.