×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: Java
Posted by: Saurabh Kumar
Added: Jan 27, 2023 1:01 AM
Views: 0
  1. /*
  2.  * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
  3.  * Click nbfs://nbhost/SystemFileSystem/Templates/GUIForms/JFrame.java to edit this template
  4.  */
  5. package com.saurabh.gui;
  6.  
  7. import com.saurabh.dbutil.DbConnection;
  8. import javax.swing.JFrame;
  9. import javax.swing.JOptionPane;
  10.  
  11. /**
  12.  *
  13.  * @author Saurabh Kumar
  14.  */
  15. public class Index extends javax.swing.JFrame {
  16.  
  17.     /**
  18.      * Creates new form Index
  19.      */
  20.     public Index() {
  21.         initComponents();
  22.         setLocationRelativeTo(null);
  23.         this.setTitle("Saurabh Kumar      Index");
  24.        
  25.        
  26.     }
  27.  
  28.     /**
  29.      * This method is called from within the constructor to initialize the form.
  30.      * WARNING: Do NOT modify this code. The content of this method is always
  31.      * regenerated by the Form Editor.
  32.      */
  33.     @SuppressWarnings("unchecked")
  34.     // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
  35.     private void initComponents() {
  36.  
  37.         buttonGroup1 = new javax.swing.ButtonGroup();
  38.         jindexframe = new javax.swing.JPanel();
  39.         jLabel1 = new javax.swing.JLabel();
  40.         jrbaddemp = new javax.swing.JRadioButton();
  41.         jrbsearchemp = new javax.swing.JRadioButton();
  42.         jrbdeleteemp = new javax.swing.JRadioButton();
  43.         jrbshowemp = new javax.swing.JRadioButton();
  44.         jbtnsubmit = new javax.swing.JButton();
  45.         jrbquit = new javax.swing.JRadioButton();
  46.         jrbupdateemp = new javax.swing.JRadioButton();
  47.  
  48.         setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
  49.  
  50.         jindexframe.setBackground(new java.awt.Color(153, 153, 255));
  51.         jindexframe.setBorder(javax.swing.BorderFactory.createEtchedBorder(javax.swing.border.EtchedBorder.RAISED));
  52.         jindexframe.setForeground(new java.awt.Color(204, 0, 0));
  53.         jindexframe.setFont(new java.awt.Font("Segoe UI", 1, 24)); // NOI18N
  54.         jindexframe.setName("Index"); // NOI18N
  55.  
  56.         jLabel1.setFont(new java.awt.Font("Segoe UI", 1, 36)); // NOI18N
  57.         jLabel1.setForeground(new java.awt.Color(255, 0, 51));
  58.         jLabel1.setText("Select Given Option");
  59.  
  60.         buttonGroup1.add(jrbaddemp);
  61.         jrbaddemp.setFont(new java.awt.Font("Rockwell Nova", 1, 24)); // NOI18N
  62.         jrbaddemp.setText("Add Employee");
  63.         jrbaddemp.setPreferredSize(new java.awt.Dimension(207, 67));
  64.  
  65.         buttonGroup1.add(jrbsearchemp);
  66.         jrbsearchemp.setFont(new java.awt.Font("Rockwell Nova", 1, 24)); // NOI18N
  67.         jrbsearchemp.setText("Search Employee");
  68.         jrbsearchemp.setPreferredSize(new java.awt.Dimension(207, 67));
  69.  
  70.         buttonGroup1.add(jrbdeleteemp);
  71.         jrbdeleteemp.setFont(new java.awt.Font("Rockwell Nova", 1, 24)); // NOI18N
  72.         jrbdeleteemp.setText("Delete Employee");
  73.         jrbdeleteemp.setPreferredSize(new java.awt.Dimension(207, 67));
  74.  
  75.         buttonGroup1.add(jrbshowemp);
  76.         jrbshowemp.setFont(new java.awt.Font("Rockwell Nova", 1, 24)); // NOI18N
  77.         jrbshowemp.setText("Show All Employee");
  78.         jrbshowemp.setPreferredSize(new java.awt.Dimension(207, 67));
  79.  
  80.         jbtnsubmit.setBackground(new java.awt.Color(153, 0, 0));
  81.         jbtnsubmit.setFont(new java.awt.Font("Segoe UI", 1, 24)); // NOI18N
  82.         jbtnsubmit.setText("SUBMIT");
  83.         jbtnsubmit.addActionListener(new java.awt.event.ActionListener() {
  84.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  85.                 jbtnsubmitActionPerformed(evt);
  86.             }
  87.         });
  88.  
  89.         buttonGroup1.add(jrbquit);
  90.         jrbquit.setFont(new java.awt.Font("Rockwell Nova", 1, 24)); // NOI18N
  91.         jrbquit.setText("QUIT");
  92.  
  93.         buttonGroup1.add(jrbupdateemp);
  94.         jrbupdateemp.setFont(new java.awt.Font("Rockwell Nova", 1, 24)); // NOI18N
  95.         jrbupdateemp.setText("Update Employee");
  96.  
  97.         javax.swing.GroupLayout jindexframeLayout = new javax.swing.GroupLayout(jindexframe);
  98.         jindexframe.setLayout(jindexframeLayout);
  99.         jindexframeLayout.setHorizontalGroup(
  100.             jindexframeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  101.             .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jindexframeLayout.createSequentialGroup()
  102.                 .addContainerGap(95, Short.MAX_VALUE)
  103.                 .addGroup(jindexframeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  104.                     .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 377, javax.swing.GroupLayout.PREFERRED_SIZE)
  105.                     .addGroup(jindexframeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
  106.                         .addComponent(jrbquit, javax.swing.GroupLayout.PREFERRED_SIZE, 357, javax.swing.GroupLayout.PREFERRED_SIZE)
  107.                         .addGroup(jindexframeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
  108.                             .addComponent(jrbshowemp, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  109.                             .addComponent(jrbdeleteemp, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  110.                             .addComponent(jrbupdateemp, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 357, Short.MAX_VALUE)
  111.                             .addComponent(jrbsearchemp, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  112.                             .addComponent(jrbaddemp, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
  113.                 .addGap(76, 76, 76))
  114.             .addGroup(jindexframeLayout.createSequentialGroup()
  115.                 .addGap(170, 170, 170)
  116.                 .addComponent(jbtnsubmit, javax.swing.GroupLayout.PREFERRED_SIZE, 176, javax.swing.GroupLayout.PREFERRED_SIZE)
  117.                 .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
  118.         );
  119.         jindexframeLayout.setVerticalGroup(
  120.             jindexframeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  121.             .addGroup(jindexframeLayout.createSequentialGroup()
  122.                 .addGap(25, 25, 25)
  123.                 .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 44, javax.swing.GroupLayout.PREFERRED_SIZE)
  124.                 .addGap(18, 18, 18)
  125.                 .addComponent(jrbaddemp, javax.swing.GroupLayout.PREFERRED_SIZE, 59, javax.swing.GroupLayout.PREFERRED_SIZE)
  126.                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
  127.                 .addComponent(jrbsearchemp, javax.swing.GroupLayout.PREFERRED_SIZE, 56, javax.swing.GroupLayout.PREFERRED_SIZE)
  128.                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
  129.                 .addComponent(jrbupdateemp, javax.swing.GroupLayout.PREFERRED_SIZE, 57, javax.swing.GroupLayout.PREFERRED_SIZE)
  130.                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
  131.                 .addComponent(jrbdeleteemp, javax.swing.GroupLayout.PREFERRED_SIZE, 59, javax.swing.GroupLayout.PREFERRED_SIZE)
  132.                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
  133.                 .addComponent(jrbshowemp, javax.swing.GroupLayout.PREFERRED_SIZE, 59, javax.swing.GroupLayout.PREFERRED_SIZE)
  134.                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
  135.                 .addComponent(jrbquit, javax.swing.GroupLayout.PREFERRED_SIZE, 53, javax.swing.GroupLayout.PREFERRED_SIZE)
  136.                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
  137.                 .addComponent(jbtnsubmit, javax.swing.GroupLayout.PREFERRED_SIZE, 61, javax.swing.GroupLayout.PREFERRED_SIZE)
  138.                 .addContainerGap(31, Short.MAX_VALUE))
  139.         );
  140.  
  141.         javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
  142.         getContentPane().setLayout(layout);
  143.         layout.setHorizontalGroup(
  144.             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  145.             .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
  146.                 .addGap(0, 0, Short.MAX_VALUE)
  147.                 .addComponent(jindexframe, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
  148.         );
  149.         layout.setVerticalGroup(
  150.             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  151.             .addComponent(jindexframe, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  152.         );
  153.  
  154.         jindexframe.getAccessibleContext().setAccessibleName("");
  155.  
  156.         pack();
  157.     }// </editor-fold>                        
  158.  
  159.     private void jbtnsubmitActionPerformed(java.awt.event.ActionEvent evt) {                                          
  160.         // TODO add your handling code here:
  161.         if(validateOpiton()== false){
  162.             JOptionPane.showMessageDialog(null,"Please Select Any one Option");
  163.             return;
  164.         }
  165.         JFrame frame=null;
  166.         if(jrbaddemp.isSelected()){
  167.             // calling frame here
  168.             frame=new Add();
  169.         }
  170.         else if(jrbshowemp.isSelected()){
  171.             frame= new Show();
  172.         }
  173.         else if(jrbdeleteemp.isSelected()){
  174.             frame = new Delete();
  175.         }
  176.         else if(jrbsearchemp.isSelected()){
  177.             frame = new Search();
  178.         }
  179.         else if(jrbupdateemp.isSelected()){
  180.             frame = new Update();
  181.         }
  182.         else if(jrbquit.isSelected()){
  183.             DbConnection.closeConnection();
  184.             System.exit(0);
  185.         }
  186.         frame.setVisible(true);
  187.         this.dispose();
  188.        
  189.     }                                          
  190.  
  191.     /**
  192.      * @param args the command line arguments
  193.      */
  194.     public static void main(String args[]) {
  195.         /* Set the Nimbus look and feel */
  196.         //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
  197.         /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
  198.          * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
  199.          */
  200.         try {
  201.             for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
  202.                 if ("Nimbus".equals(info.getName())) {
  203.                     javax.swing.UIManager.setLookAndFeel(info.getClassName());
  204.                     break;
  205.                 }
  206.             }
  207.         } catch (ClassNotFoundException ex) {
  208.             java.util.logging.Logger.getLogger(Index.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  209.         } catch (InstantiationException ex) {
  210.             java.util.logging.Logger.getLogger(Index.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  211.         } catch (IllegalAccessException ex) {
  212.             java.util.logging.Logger.getLogger(Index.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  213.         } catch (javax.swing.UnsupportedLookAndFeelException ex) {
  214.             java.util.logging.Logger.getLogger(Index.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  215.         }
  216.         //</editor-fold>
  217.  
  218.         /* Create and display the form */
  219.         java.awt.EventQueue.invokeLater(new Runnable() {
  220.             public void run() {
  221.                 new Index().setVisible(true);
  222.             }
  223.         });
  224.     }
  225.  
  226.     // Variables declaration - do not modify                    
  227.     private javax.swing.ButtonGroup buttonGroup1;
  228.     private javax.swing.JLabel jLabel1;
  229.     private javax.swing.JButton jbtnsubmit;
  230.     private javax.swing.JPanel jindexframe;
  231.     private javax.swing.JRadioButton jrbaddemp;
  232.     private javax.swing.JRadioButton jrbdeleteemp;
  233.     private javax.swing.JRadioButton jrbquit;
  234.     private javax.swing.JRadioButton jrbsearchemp;
  235.     private javax.swing.JRadioButton jrbshowemp;
  236.     private javax.swing.JRadioButton jrbupdateemp;
  237.     // End of variables declaration                  
  238.  
  239.     private boolean validateOpiton() {
  240.         if(buttonGroup1.getSelection()==null)
  241.             return false;
  242.         return true;
  243.     }
  244. }
  245.