9 Replies Latest reply on Mar 12, 2018 2:15 PM by hphanjra-JavaNet

    Code throwing Null exceptoin

    hphanjra-JavaNet

      package FinCal; /* * select * from cts_cus select * from cts_shifts drop table cts_cus go CREATE TABLE [dbo].[cts_cus]( [day] [varchar](10) NULL, [fac_name] [varchar](20) NULL, [last_name] [varchar](10) NULL ) ON [PRIMARY] drop table cts_shifts go CREATE TABLE [dbo].[cts_shifts]( [day] [varchar](20) primary key, [fac_name] [varchar](20) NULL, [candi_type] [varchar](10) NULL, [f_7_3] [varchar](10) NULL, [f_3_11] [varchar](10) NULL, [f_11_7] [varchar](10) NULL ) */ import java.awt.Color; import java.awt.Rectangle; import javax.swing.JPanel; import javax.swing.JButton; import javax.swing.UIManager; import javax.swing.border.TitledBorder; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import javax.swing.JLabel; import javax.swing.JComboBox; import javax.swing.DefaultComboBoxModel; import javax.swing.JSpinner; import javax.swing.SpinnerDateModel; import com.sun.org.apache.bcel.internal.generic.INSTANCEOF; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Calendar; import java.beans.PropertyChangeListener; import java.beans.PropertyChangeEvent; import java.awt.event.InputMethodListener; import java.awt.event.InputMethodEvent; import javax.swing.event.ChangeListener; import javax.swing.event.ChangeEvent; public class Shifts extends JPanel { JButton btnNewButton = new JButton("Save"); JComboBox comboBox_4 = new JComboBox(); DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); String ystr = dateFormat.format(new Date ()); ComboCount combcnt = new ComboCount(); JComboBox comboBox_5 = new JComboBox(); /** * Create the panel. */ public Shifts() { setLayout(null); setEnabled(false); setBounds(new Rectangle(100, 100, 700, 600)); setBorder(new TitledBorder(UIManager.getBorder("TitledBorder.border"), "Enter Shifts", TitledBorder.LEADING, TitledBorder.TOP, null, new Color(0, 0, 0))); setLayout(null); JLabel lblFacility = new JLabel("Facility"); lblFacility.setBounds(42, 84, 69, 14); add(lblFacility); JLabel label = new JLabel("7-3"); label.setBounds(284, 84, 46, 14); add(label); JLabel label_1 = new JLabel("3-11"); label_1.setBounds(377, 84, 46, 14); add(label_1); JLabel label_2 = new JLabel("11-3"); label_2.setBounds(449, 84, 46, 14); add(label_2); JComboBox comboBox = new JComboBox(); // comboBox.setModel(new DefaultComboBoxModel(new String[] {"CNA", "LPN", "RN", "HHA", "CMA"})); comboBox.setModel(CandiPanel.candiTypecomboBox.getModel()); comboBox.setBounds(176, 128, 57, 20); add(comboBox); JComboBox comboBox_1 =  new JComboBox(); comboBox_1.setModel(new DefaultComboBoxModel(new String[] {"0","1", "2", "3", "4", "5", "6", "7", "8", "9", "10"})); comboBox_1.setBounds(271, 128, 46, 20); add(comboBox_1); JComboBox comboBox_2 =  new JComboBox(); comboBox_2.setModel(new DefaultComboBoxModel(new String[] {"0","1", "2", "3", "4", "5", "6", "7", "8", "9"})); comboBox_2.setBounds(364, 128, 46, 20); add(comboBox_2); JComboBox comboBox_3 = combcnt.getComboBox(); comboBox_3.setModel(new DefaultComboBoxModel(new String[] {"0","1", "2", "3", "4", "5", "6", "7", "8", "9"})); comboBox_3.setBounds(434, 128, 46, 20); add(comboBox_3); JLabel lblBook = new JLabel("Book"); lblBook.setBounds(176, 84, 69, 14); add(lblBook); comboBox_4.setModel(new DefaultComboBoxModel(new String[] {"select dept"})); comboBox_4.setBounds(30, 128, 115, 20); add(comboBox_4);     Object js = new Date(); JSpinner spinner = new JSpinner(); spinner.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent arg0) {   System.out.println( " State changed position Shift input --->"+spinner.getValue()); ystr = dateFormat.format(spinner.getValue()); } }); spinner.addInputMethodListener(new InputMethodListener() { public void caretPositionChanged(InputMethodEvent arg0) {   System.out.println( " Caret position Shift input --->"+ystr); } public void inputMethodTextChanged(InputMethodEvent arg0) {   System.out.println( " Input MethodShift input --->"+ystr); } }); spinner.addPropertyChangeListener(new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent arg0) { System.out.println("Property changed --------------->>"+spinner.getValue()); ChangeListener ch; } }); spinner.setModel(new SpinnerDateModel(new Date(), null, null, Calendar.DAY_OF_WEEK_IN_MONTH)); spinner.setBounds(30, 309, 115, 20); //     if  (spinner.getValue().getClass().getName())  ); add(spinner); spinner.addChangeListener(new ChangeListener() {         @Override         public void stateChanged(ChangeEvent e) {             System.out.println("value changed: " + spinner.getValue());         }     }); //// System.out.println(ystr+" <--ddddddddddddddddddd"+spinner.getValue()); btnNewButton.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent arg0) {   String tstr =  comboBox_4.getSelectedItem().toString()+ " , "+comboBox.getSelectedItem().toString()+ " , " + comboBox_1.getSelectedItem().toString()   + " , " + comboBox_2.getSelectedItem().toString()+ " , " + comboBox_3.getSelectedItem().toString()   + " , "+ystr  ;     System.out.println( " Shift input --->"+tstr);           CalendarProgram1.insertShifts(tstr);           } }); btnNewButton.setBounds(137, 386, 89, 23); add(btnNewButton); comboBox_5.setBounds(30, 174, 115, 20); add(comboBox_5); JComboBox comboBox_6 = new JComboBox(); comboBox_6.setModel(new DefaultComboBoxModel(new String[] {"CNA", "LPN"})); comboBox_6.setBounds(176, 174, 57, 20); add(comboBox_6); JComboBox comboBox_7 = new JComboBox(); comboBox_7.setModel(new DefaultComboBoxModel(new String[] {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9"})); comboBox_7.setBounds(271, 174, 46, 20); add(comboBox_7); JComboBox comboBox_8 = new JComboBox(); comboBox_8.setModel(new DefaultComboBoxModel(new String[] {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9"})); comboBox_8.setBounds(364, 174, 46, 20); add(comboBox_8); JComboBox comboBox_9 = new JComboBox(); comboBox_9.setModel(new DefaultComboBoxModel(new String[] {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9"})); comboBox_9.setBounds(434, 174, 46, 20); add(comboBox_9); } } class ComboCount{ JComboBox comboBox_1 = new JComboBox(); ComboCount(){ comboBox_1.setModel(new DefaultComboBoxModel(new String[] {"0","1", "2", "3", "4", "5", "6", "7", "8", "9", "10"})); } JComboBox getComboBox() { return comboBox_1; } }

        • 1. Re: Code throwing Null exceptoin
          hphanjra-JavaNet

          sorry about the messy code

           

          [code]

          package FinCal;

          /*
          * select * from cts_cus
          select * from cts_shifts

           

          drop table cts_cus
          go
          CREATE TABLE [dbo].[cts_cus](
          [day] [varchar](10) NULL,
          [fac_name] [varchar](20) NULL,
          [last_name] [varchar](10) NULL
          ) ON [PRIMARY]


          drop table cts_shifts
          go
          CREATE TABLE [dbo].[cts_shifts](
          [day] [varchar](20) primary key,
          [fac_name] [varchar](20) NULL,
          [candi_type] [varchar](10) NULL,
          [f_7_3] [varchar](10) NULL,
          [f_3_11] [varchar](10) NULL,
          [f_11_7] [varchar](10) NULL
          )


          */
          import java.awt.Color;
          import java.awt.Rectangle;

          import javax.swing.JPanel;
          import javax.swing.JButton;
          import javax.swing.UIManager;
          import javax.swing.border.TitledBorder;

          import java.awt.event.MouseAdapter;
          import java.awt.event.MouseEvent;

          import javax.swing.JLabel;
          import javax.swing.JComboBox;
          import javax.swing.DefaultComboBoxModel;
          import javax.swing.JSpinner;
          import javax.swing.SpinnerDateModel;

          import com.sun.org.apache.bcel.internal.generic.INSTANCEOF;

          import java.text.DateFormat;
          import java.text.SimpleDateFormat;
          import java.util.Date;
          import java.util.Calendar;
          import java.beans.PropertyChangeListener;
          import java.beans.PropertyChangeEvent;
          import java.awt.event.InputMethodListener;
          import java.awt.event.InputMethodEvent;
          import javax.swing.event.ChangeListener;
          import javax.swing.event.ChangeEvent;

          public class Shifts extends JPanel {
          JButton btnNewButton = new JButton("Save");
          JComboBox comboBox_4 = new JComboBox();
          DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
          String ystr = dateFormat.format(new Date ());
          ComboCount combcnt = new ComboCount();
          JComboBox comboBox_5 = new JComboBox();




          /**
            * Create the panel.
            */
          public Shifts() {
            setLayout(null);
           
            setEnabled(false);
            setBounds(new Rectangle(100, 100, 700, 600));
            setBorder(new TitledBorder(UIManager.getBorder("TitledBorder.border"), "Enter Shifts", TitledBorder.LEADING, TitledBorder.TOP, null, new Color(0, 0, 0)));
            setLayout(null);
           
           
           
            JLabel lblFacility = new JLabel("Facility");
            lblFacility.setBounds(42, 84, 69, 14);
            add(lblFacility);
           
            JLabel label = new JLabel("7-3");
            label.setBounds(284, 84, 46, 14);
            add(label);
           
            JLabel label_1 = new JLabel("3-11");
            label_1.setBounds(377, 84, 46, 14);
            add(label_1);
           
            JLabel label_2 = new JLabel("11-3");
            label_2.setBounds(449, 84, 46, 14);
            add(label_2);
           
            JComboBox comboBox = new JComboBox();
          // comboBox.setModel(new DefaultComboBoxModel(new String[] {"CNA", "LPN", "RN", "HHA", "CMA"}));
            comboBox.setModel(CandiPanel.candiTypecomboBox.getModel());
            comboBox.setBounds(176, 128, 57, 20);
            add(comboBox);
           
            JComboBox comboBox_1 =  new JComboBox();
             comboBox_1.setModel(new DefaultComboBoxModel(new String[] {"0","1", "2", "3", "4", "5", "6", "7", "8", "9", "10"}));
            comboBox_1.setBounds(271, 128, 46, 20);
            add(comboBox_1);

           
            JComboBox comboBox_2 =  new JComboBox();
             comboBox_2.setModel(new DefaultComboBoxModel(new String[] {"0","1", "2", "3", "4", "5", "6", "7", "8", "9"}));
            comboBox_2.setBounds(364, 128, 46, 20);
            add(comboBox_2);

            JComboBox comboBox_3 = combcnt.getComboBox();
             comboBox_3.setModel(new DefaultComboBoxModel(new String[] {"0","1", "2", "3", "4", "5", "6", "7", "8", "9"}));
            comboBox_3.setBounds(434, 128, 46, 20);
            add(comboBox_3);
           

           
           
            JLabel lblBook = new JLabel("Book");
            lblBook.setBounds(176, 84, 69, 14);
            add(lblBook);
           
            comboBox_4.setModel(new DefaultComboBoxModel(new String[] {"select dept"}));
            comboBox_4.setBounds(30, 128, 115, 20);
           
            add(comboBox_4);
           
                Object js = new Date();
            JSpinner spinner = new JSpinner();
            spinner.addChangeListener(new ChangeListener() {
             public void stateChanged(ChangeEvent arg0) {
                 System.out.println( " State changed position Shift input --->"+spinner.getValue());
               ystr = dateFormat.format(spinner.getValue()); 
             }
            });
            spinner.addInputMethodListener(new InputMethodListener() {
             public void caretPositionChanged(InputMethodEvent arg0) {
                 System.out.println( " Caret position Shift input --->"+ystr);  
             }
            
             public void inputMethodTextChanged(InputMethodEvent arg0) {
                 System.out.println( " Input MethodShift input --->"+ystr);   
             }
            });
            spinner.addPropertyChangeListener(new PropertyChangeListener() {
             public void propertyChange(PropertyChangeEvent arg0) {
              System.out.println("Property changed --------------->>"+spinner.getValue());
            
              ChangeListener ch;
             }
            });
            spinner.setModel(new SpinnerDateModel(new Date(), null, null, Calendar.DAY_OF_WEEK_IN_MONTH));
            spinner.setBounds(30, 309, 115, 20);
           
           
          //     if  (spinner.getValue().getClass().getName())  );
            add(spinner);
           
             spinner.addChangeListener(new ChangeListener() {

                    @Override
                    public void stateChanged(ChangeEvent e) {
                        System.out.println("value changed: " + spinner.getValue());
                    }
                });

           
           
          //// System.out.println(ystr+" <--ddddddddddddddddddd"+spinner.getValue());
            btnNewButton.addMouseListener(new MouseAdapter() {
             @Override
             public void mouseClicked(MouseEvent arg0) {
                String tstr =  comboBox_4.getSelectedItem().toString()+ " , "+comboBox.getSelectedItem().toString()+ " , " + comboBox_1.getSelectedItem().toString()
                  + " , " + comboBox_2.getSelectedItem().toString()+ " , " + comboBox_3.getSelectedItem().toString()
                  + " , "+ystr  ;
               
               System.out.println( " Shift input --->"+tstr);
                     CalendarProgram1.insertShifts(tstr);
                   
            
             
             }
            });
            btnNewButton.setBounds(137, 386, 89, 23);
            add(btnNewButton);
           

            comboBox_5.setBounds(30, 174, 115, 20);
            add(comboBox_5);
           
            JComboBox comboBox_6 = new JComboBox();
            comboBox_6.setModel(new DefaultComboBoxModel(new String[] {"CNA", "LPN"}));
            comboBox_6.setBounds(176, 174, 57, 20);
            add(comboBox_6);
           
            JComboBox comboBox_7 = new JComboBox();
            comboBox_7.setModel(new DefaultComboBoxModel(new String[] {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9"}));
            comboBox_7.setBounds(271, 174, 46, 20);
            add(comboBox_7);
           
            JComboBox comboBox_8 = new JComboBox();
            comboBox_8.setModel(new DefaultComboBoxModel(new String[] {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9"}));
            comboBox_8.setBounds(364, 174, 46, 20);
            add(comboBox_8);
           
            JComboBox comboBox_9 = new JComboBox();
            comboBox_9.setModel(new DefaultComboBoxModel(new String[] {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9"}));
            comboBox_9.setBounds(434, 174, 46, 20);
            add(comboBox_9); 
           
          }
          }

          class ComboCount{
          JComboBox comboBox_1 = new JComboBox();
          ComboCount(){
          comboBox_1.setModel(new DefaultComboBoxModel(new String[] {"0","1", "2", "3", "4", "5", "6", "7", "8", "9", "10"}));
          }
          JComboBox getComboBox() {
            return comboBox_1;
          }

          }

           

          [/code]

          • 2. Re: Code throwing Null exceptoin
            hphanjra-JavaNet

            /*

            Dashboard learning as swing classes excercise.

            Build a standalone gui to assign task


            delete from cts_cus
            delete from cts_shifts
            delete from assignment

            select * from cts_cus
            select * from cts_shifts
            select * from assignment

            select day,fac_name,candi_type,  f_7_3 ,f_3_11,f_11_7
            , f1, f2, f3,  f4,  f5,  f6,  f7,  f8, f9,  f10
            from mytest_vw
            order by 1,2,3

            select * from assignment_status

            select * from  cts_candi

            drop table cts_candi

            create table cts_candi
            (fname   varchar(10),
            lname  varchar(10),
            type   varchar(20)
            )

            drop table cts_shifts
            go
            CREATE TABLE [dbo].[cts_shifts](
                [Id] int IDENTITY(1,1) NOT NULL PRIMARY KEY,
            [day] [varchar](20) ,
            [fac_name] [varchar](20) NULL,
            [candi_type] [varchar](10) NULL,
            [f_7_3] int NULL,
            [f_3_11] int NULL,
            [f_11_7] int NULL,
            [f_7_3_who] varchar(20) NULL,
            [f_3_11_who] varchar(20) NULL,
            [f_11_7_who] varchar(20) NULL,
            [f_7_3_ti] varchar(20) NULL,
            [f_7_3_to] varchar(10) NULL,
            [f_3_11_ti] varchar(10) NULL,
            [f_3_11_to] varchar(10) NULL,
            [f_11_7_ti] varchar(10) NULL,
            [f_11_7_to] varchar(10) NULL,
                comments     varchar(30)
            )
            drop view assignment_status

            create view assignment_status
            as
              select b.day as bday,b.fac_name as bfac_name, b.candi_type as bcandi_type,a.day,a.fac_name,canditype,count(*) as booked
              ,whod
              from mytest_vw b
              LEFT OUTER JOIN assignment a
              ON
               a.day = b.day
              and a.fac_name = b.fac_name
              and a.canditype = b.candi_type
              group by  b.day,b.fac_name, b.candi_type,a.day,a.fac_name,canditype,whod

            insert into assignment values('2018-01-31','Hudson','333-222-1111','LPN','7-3','HAWA','777-222-6665','this is a commment',null)

            insert into assignment values('2017-12-06','sss','333-222-1111','CNA','7-3','HAWA','777-222-6665','this is a commment',null)
            go
            insert into assignment values('2017-12-11','sss','333-222-1111','CNA','7-3','HTRW','777-222-6665','this is a commment',null)
            go
            insert into assignment values('2017-12-11','sss','333-222-1111','CNA','7-3','TTTT','777-222-6665','this is a commment',null)
            go
            insert into assignment values('2018-01-06','BISHOP','333-222-1111','LPN','7-3','HTRW','777-222-6665','this is a commment',null)

            drop table assignment
            go
            create table assignment
            (day  varchar(10),
            fac_name varchar(10),
            fac_ph1 varchar(13),
            canditype  varchar(10),
            shift  varchar(10),
            whod  varchar(10),
            who_ph  varchar(13),
            comments varchar(30),
            cancelled  varchar(10)
            )

             

             

             

            drop view mytest_vw
            go
            create view mytest_vw
            as
            select day,fac_name,candi_type, f_7_3 as f_7_3
            , f_3_11 as f_3_11
            , f_11_7 as f_11_7 
            ,'f1' as f1
            ,'f2' as f2
            ,'f3' as f3
            ,'f4' as f4
            ,'f5' as f5
            ,'f6' as f6
            ,'f7' as f7
            ,'f8' as f8
            ,'f9' as f9
            ,'f10' as f10
            from cts_shifts
            --group by day,fac_name,candi_type

             

            select * from mytest_vw

            delete from cts_cus
            go
            delete from cts_shifts

            drop table cts_cus
            go
            CREATE TABLE [dbo].[cts_cus](
            [day] [varchar](10) NULL,
            [fac_name] [varchar](20) NULL,
            [last_name] [varchar](10) NULL
            ) ON [PRIMARY]

            drop table cts_shifts
            go

            drop table cts_shifts
            go
            CREATE TABLE [dbo].[cts_shifts](
                [Id] int IDENTITY(1,1) NOT NULL PRIMARY KEY,
            [day] [varchar](20) ,
            [fac_name] [varchar](20) NULL,
            [candi_type] [varchar](10) NULL,
            [f_7_3] int NULL,
            [f_3_11] int NULL,
            [f_11_7] int NULL
            )

            */

            package FinCal;

            import javafx.scene.layout.Border;

            import javax.swing.*;
            import javax.swing.border.TitledBorder;
            import javax.swing.event.*;
            import javax.swing.table.*;
            import javax.swing.text.DefaultCaret;
            import javax.swing.text.SimpleAttributeSet;
            import javax.swing.text.StyleConstants;
            import javax.swing.text.StyledDocument;

            import java.awt.*;
            import java.util.List;
            import java.util.*;
            import java.awt.event.*;
            import java.sql.Connection;
            import java.sql.DriverManager;
            import java.sql.PreparedStatement;
            import java.sql.ResultSet;
            import java.sql.SQLException;
            import java.util.*;
            import java.util.Timer;
            import java.awt.*;

            import javax.swing.*;

             

            public class CalendarProgram1{
            static JTextArea textarea;
                static JLabel lblMonth, lblYear;
                static JButton btnPrev, btnNext;
                static JTable tblCalendar;
                static JComboBox cmbYear;
                static JFrame frmMain;
                static Container pane;
                static DefaultTableModel mtblCalendar; //Table model
                static JScrollPane stblCalendar; //The scrollpane
                static JPanel pnlCalendar;
                static int realYear, realMonth, realDay, currentYear, currentMonth;
                static String[][][] mytext= new String [4][4][100];
               /// static CalPanel calPanel = new CalPanel();
                static boolean alreadyOpened = false;
                static CalFrame cf = null; //new CalFrame();
                static ClientPanel cpanel = null;
                static CandiPanel candipanel = null;
                static  Assignment  assignment = null ; //new Assignment();
               static Shifts shifts = null;
              
                static MiscDatabaseTasks mis = new MiscDatabaseTasks();
                static String[][][] allContent = new String[2][3000][3000];
                static int I = 2;
                static int J = 3;
                static HashMap AllShifts = new HashMap();
               
                static Map<String, List<String>> hmShifts = new HashMap<String, List<String>>();
                static Map<String, List<String>> assignmentStatus = new HashMap<String, List<String>>();

               
                static int daySize = 11;
            static String viewingDay = " ";
            static String selectedPeriod = " ";

            static boolean seven = false;
            static boolean three  = false;
            static boolean eleven = false;
            static String sftWhere = " ";

               
                public static void printTemp() {
                 for (int i=0;i<I;i++) {
                  for (int j=0;j<J;j++) {
                    System.out.print(" allContent["+i+"]["+j+"]"+allContent[i][j][0]); 
                  }
                  System.out.println();
                 }
                }
                public static void popluateTemp() {
                    String name = "Har";
                    String title = "CN";
                    String hired = "YES";
                 for (int i=0;i<I;i++) {
                  for (int j=0;j<J;j++) {
                    allContent[i][j][0]= name+" "+i+" "+j; 
                  }
                 
                 }
                  
                }
                public static void main (String args[]){
                   candipanel = new CandiPanel();
                 popluateTemp();
                 printTemp();
                 //System.exit(0);
                
                 Connection con = null;
                
                   mytext[0][0][0] = "har";
                   mytext[0][0][2] = "Rav";
                  
                    try {UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());}
                    catch (ClassNotFoundException e) {}
                    catch (InstantiationException e) {}
                    catch (IllegalAccessException e) {}
                    catch (UnsupportedLookAndFeelException e) {}
                   
                    //Prepare frame
                    frmMain = new JFrame ("Gestionnaire de clients"); //Create frame
                 //   frmMain.setSize(330, 375); //Set size to 400x400 pixels
                     frmMain.setSize(1050,950); //Set size to 400x400 pixels
                    frmMain.setResizable(true);
                    pane = frmMain.getContentPane(); //Get content pane
                    pane.setLayout(null); //Apply null layout
                    frmMain.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //Close when X is clicked
                   
                    //Create controls
                    lblMonth = new JLabel ("January");
                    lblYear = new JLabel ("Change year:");
                    cmbYear = new JComboBox();
                   // btnPrev = new JButton ("&lt;&lt;Next");
                    //btnNext = new JButton ("&gt;&gt;");
                    btnPrev = new JButton ("Prev");
                    btnNext = new JButton ("Next");
                   
                    mtblCalendar = new DefaultTableModel(){public boolean isCellEditable(int rowIndex, int mColIndex){return false;}};
                    tblCalendar = new JTable(mtblCalendar);
                   
                  //  tblCalendar.getColumn("").setCellRenderer(new TextAreaRenderer());
                    //tblCalendar.getColumn("FD").setCellRenderer(cellRenderer);

                    stblCalendar = new JScrollPane(tblCalendar);
                    pnlCalendar = new JPanel(null);
                    ClientForm cform = new  ClientForm(" fdsf","ss");
              
                    //Set border
                    pnlCalendar.setBorder(BorderFactory.createTitledBorder("Calendar"));
                   
                    //Register action listeners
                    btnPrev.addActionListener(new btnPrev_Action());
                    btnNext.addActionListener(new btnNext_Action());
                    cmbYear.addActionListener(new cmbYear_Action());
                   
                    //Add controls to pane
                    MainControl mc = new MainControl();
                   // pane.add(pnlCalendar);
                //   mc.setBounds(0, 0, 100, 200);

             

                   mc.setVisible(true);
                   pane.add(mc);
              mc.btnNewButton_1.addMouseListener(new MouseAdapter() {
               @Override
               public void mouseClicked(MouseEvent arg0) {
                System.out.println(" Shifts in Calendar");

                 try {  pane.remove(pnlCalendar);
                 }catch(Exception e) {}
                 try {  
                 pane.remove(cpanel);
                 }catch(Exception e) {}

                 try { 
                  pane.remove(cpanel);
                  }catch(Exception e) {}
                 try {  
                 pane.remove(cpanel);
                 }catch(Exception e) {}
                 try {  
                  //pane.remove(shifts);
                  }catch(Exception e) {}

                 try {  
                  pane.remove(candipanel);
                  }catch(Exception e) {}
             
                 try {  
                  pane.remove(assignment);
                  }catch(Exception e) {}
             
                  pane.revalidate();
                  pane.repaint(); 
                
                  shifts = new Shifts();
                  getFacilities("ssss,fss  ");
                  // pane.remove(mc);
                //  cpanel = new ClientPanel();
                  shifts.setVisible(true);
                    pane.add(shifts);
                  //  System.out.println(" shifti panel added");
                   pane.revalidate();
                   pane.repaint();
                  
               }
              });
             
                   mc.btnNewCandidate.addMouseListener(new MouseAdapter() {
               @Override
               public void mouseClicked(MouseEvent arg0) {
               
                System.out.println(" Enter Candidate button pressed");
               
                 try {  pane.remove(pnlCalendar);
                 }catch(Exception e) {}
                 try {  
                 pane.remove(cpanel);
                 }catch(Exception e) {}

                 try { 
                  pane.remove(cpanel);
                  }catch(Exception e) {}
                 try {  
                 pane.remove(cpanel);
                 }catch(Exception e) {}
                 try {  
                  pane.remove(shifts);
                  }catch(Exception e) {}

                 try {  
                  pane.remove(candipanel);
                  }catch(Exception e) {}
             
                 try {  
                  pane.remove(assignment);
                  }catch(Exception e) {}
             
                  pane.revalidate();
                  pane.repaint(); 

                  candipanel = new CandiPanel();
                  // pane.remove(mc);
                //  cpanel = new ClientPanel();
                  candipanel.btnNewButton_1.addMouseListener(new MouseAdapter() {
                  @Override
                  public void mouseClicked(MouseEvent arg0) {
                   System.out.println(" Inserting candidate ---------->");
                   insertCandi();
                  }
                 });
                  candipanel.setVisible(true);
                    pane.add(candipanel);
                    System.out.println(" Candi panel added");
                   pane.revalidate();
                   pane.repaint(); 
                  
               }
              });
                  
                
                     
              mc.btnAssigments.addMouseListener(new MouseAdapter() {
               @Override
               public void mouseClicked(MouseEvent arg0) {
                
                 getAssignmentStatus();
                 try {  pane.remove(pnlCalendar);
                  }catch(Exception e) {}
                 try {  
                 pane.remove(cpanel);
                 }catch(Exception e) {}

                 try { 
                  //pane.remove(cpanel);
                  }catch(Exception e) {}
                 try {  
                 pane.remove(cpanel);
                 }catch(Exception e) {}
                 try {  
                  pane.remove(shifts);
                  }catch(Exception e) {}

                 try {  
                  pane.remove(candipanel);
                  }catch(Exception e) {}
                 try {  
                  pane.remove(assignment);     
                  }catch(Exception e) {}
             
                  pane.revalidate();
                  pane.repaint(); 

                //  getFacilities("ssss,fss  ");
                  assignment = new Assignment();
                 
            /*
                  assignment.faclist.removeAllItems();
                  for (int t = 0; t <  shifts.comboBox_4.getItemCount(); t++)
                  {
                   assignment.faclist.addItem( shifts.comboBox_4.getItemAt(t));
                 
                  }
                  */
                  System.out.println(" ((((((((((((((((((((((((((-->"+assignmentStatus.size());
                  Set <String> ke=  assignmentStatus.keySet();
                  for (int t = 0; t <  assignmentStatus.keySet().size(); t++)
                  {
                   System.out.println(" ((((((((((((((((((((((((((-->"+assignmentStatus.get(t));
                //   System.out.println(" ((((((((((((((((((((((((((-->"+ke.);
                   

                   
                  }
                 
                  assignment.bookDate.addActionListener(new ActionListener() {
                  public void actionPerformed(ActionEvent arg0) {
                  
                   //System.out.println("  Action listner for book date -------------------->");
                         System.out.println(" AddItem Listner ss Select ITem is ---->"+ke.size()); 
                         selectedPeriod  = (String)assignment.bookDate.getSelectedItem();
                      System.out.println( " refreshing...: "+  selectedPeriod);
                       // refreshAssignmentDate(ke);   
                        refreshAssignment(ke);
                  
                  }
                 });
                 
                 assignment.shift_detail.addActionListener(new ActionListener() {
                  public void actionPerformed(ActionEvent arg0) {
                                    
                     refreshShiftDetail();

                   System.out.println( " seven -->"+seven);
                  }
                 });
                 
                
                 assignment.btnSave.addActionListener(new ActionListener() {
                  public void actionPerformed(ActionEvent arg0) {
                   System.out.println(" btn save clicked");
                   updateShift();
                    refreshShiftDetail();
                  
                  
                  }
                 });
                
                 
            /*
                      assignment.bookDate.addItemListener(new ItemListener() {
                  public void itemStateChanged(ItemEvent arg0) {
                        System.out.println(" AddItem Listner ss Select ITem is ---->"+ke.size()); 
                        selectedPeriod  = (String)assignment.bookDate.getSelectedItem();
                     System.out.println( " refreshing...: "+  selectedPeriod);
                      // refreshAssignmentDate(ke);   
                       refreshAssignment(ke);

                  }

                      });
                      */
               
                     refreshAssignmentDate(ke);
                //  refreshAssignment(ke);
                 
                  /*
                     Iterator<String> it = ke.iterator();
                 
                     while(it.hasNext()){
                      String item = it.next();
                        System.out.println("KKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD"+assignmentStatus);
                        assignment.bookDate.addItem(item);
                  List ks = assignmentStatus.get(item);
                      System.out.println(item+"LIST    KKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD"+ks);
                    
                        System.out.println("@@@@@@@@@@@@@@@@@@@@@@@@@"+ks.size());
                         
                       
                       
                      Object[] numbers = ks.toArray();
                      System.out.println("@@@@@@@@@@@@@@@@@@@@@@@@@"+numbers[1]);
                      String tstring = " ";
                      int itr = ks.size();
                      for (int y=1;y<ks.size();) {          
                       System.out.println("*************************"+numbers[y-1]);
                       System.out.println("*************************"+numbers[y]);
                       System.out.println("*************************"+numbers[y+1]);
                       System.out.println("*************************"+numbers[y+2]);
                       System.out.println("*************************"+numbers[y+3]);
                       System.out.println("*************************"+numbers[y+4]);
                       System.out.println("*************************"+numbers[y+5]);
                       System.out.println("*************************"+numbers[y+6]);
                       System.out.println("*************************"+numbers[y+7]);
                       System.out.println("*************************"+numbers[y+8]);          
                       String this_item=  numbers[y-1]
                       + " "+numbers[y]
                        +numbers[y+1] +numbers[y+5]; 
                      
                    System.out.println(item  + " : "+  selectedPeriod);
                   
                   assignment.shift_detail.addItem(this_item);          
                   y=y+11;         
                      }           
                        assignment.whoD.addItem(ks.get(1));
            //           assignment.shift_detail.addItem(ks);           
                     }

                    
                     */
                 
                //  cpanel.setVisible(true);
                //assignment.faclist.add(  shifts.comboBox_4.getComponents());
                  // pane.remove(mc);
                    pane.add(assignment);
                   pane.revalidate();
                   pane.repaint();   
               }
              });

             
                   mc.btnNewClient.addMouseListener(new MouseAdapter() {
               @Override
               public void mouseClicked(MouseEvent arg0) {   
                System.out.println(" Enter Client button pressed");

              
                   try {  pane.remove(pnlCalendar);
                    }catch(Exception e) {}
                   try {  
                   pane.remove(cpanel);
                   }catch(Exception e) {}

                   try { 
                    //pane.remove(cpanel);
                    }catch(Exception e) {}
                   try {  
                   pane.remove(cpanel);
                   }catch(Exception e) {}
                   try {  
                    pane.remove(shifts);
                    }catch(Exception e) {}

                   try {  
                    pane.remove(candipanel);
                   
                   }catch(Exception e) {}
               
                    
                    try {  
                     pane.remove(assignment);

                   }catch(Exception e) {}
                
                   
                    pane.revalidate();
                    pane.repaint(); 

              
                    cpanel = new ClientPanel();
                    cpanel.setVisible(true);
                    // pane.remove(mc);
                      pane.add(cpanel);
                     pane.revalidate();
                     pane.repaint(); 
              
              
              
              
              
              
               }
              });
             
              mc.btnNewButton.addMouseListener(new MouseAdapter() {
               @Override
               public void mouseClicked(MouseEvent arg0) {
               
                System.out.println(" calender is clicked");
               
                       getAssignmentStatus();
                       getAllFac();
                 try {  pane.remove(pnlCalendar);
                  }catch(Exception e) {}
                 try {  
                 pane.remove(cpanel);
                 }catch(Exception e) {}

                 try {  pane.remove(cpanel);
                  }catch(Exception e) {}
                 try {  
                 pane.remove(cpanel);
                 }catch(Exception e) {}
                 try {  
                  pane.remove(shifts);
                  }catch(Exception e) {}

                 try {  
                  pane.remove(candipanel);
                  }catch(Exception e) {}
                 try {  
                  pane.remove(assignment);
                  }catch(Exception e) {}
             
             
                  pane.revalidate();
                  pane.repaint(); 

                try {
                
                 System.out.println("Calling getCal INfo -------------------------------------*********************");
                // getCalInfo();
               
                }catch(Exception e) {System.out.println(e);
                }
               
                System.out.println(" Calendar button pressed");
                 pane.add(pnlCalendar);
                // pane.remove(mc);
                 pane.revalidate();
                 pane.repaint();
               }
              });
                  pane.revalidate();
                     
                    pnlCalendar.add(lblMonth);
                    pnlCalendar.add(lblYear);
                    pnlCalendar.add(cmbYear);
                    pnlCalendar.add(btnPrev);
                    pnlCalendar.add(btnNext);
                    pnlCalendar.add(stblCalendar);
                  
                   
                    tblCalendar.addMouseListener(new java.awt.event.MouseAdapter() {
                             JInterFrame jif = null;
                         //    DayDetail dd = null ;
                     boolean isAlreadyOneClick = false;
                        public void mouseClicked(java.awt.event.MouseEvent evt) {
                            int row = tblCalendar.rowAtPoint(evt.getPoint());
                            int col = tblCalendar.columnAtPoint(evt.getPoint());
                            System.out.println("evt"+evt);
                           ///-- if(evt.getClickCount()==1){
                                if (row >= 0 && col >= 0) {
                                System.out.println(evt.getClickCount()+"Row clicked -->"+row + " Column clicked -->"+col); //......; //

                               //  }
                              }
                           
                         
                                System.out.println("double click");
                               
                                if (isAlreadyOneClick  && !alreadyOpened  ) {
                                //    if (isAlreadyOneClick  ) {

                                 //   jif = new JInterFrame();
                                //    dd = new DayDetail();
                               
                                   // jif.setVisible(true);
                                    cf = new CalFrame();
                                 
                                    cf.addWindowListener(new java.awt.event.WindowAdapter() {

                               @Override
                               public void windowClosing(java.awt.event.WindowEvent arg0) {
                                 System.out.println(arg0.WINDOW_CLOSING+")))))))))))))))))))))))))))))))))))))))))))))))))))))"+evt);
                                 if (arg0.WINDOW_CLOSING == 201) {
                                 alreadyOpened = false ;
                                 }
                                
                               }
                              });
                                   
                                   JButton jsb = new JButton("KK");
                                   cf.getContentPane().add(jsb);
                                   cf.textArea_1.setText("viewingDay "+viewingDay+"\n line 2");
                                  // cf.textArea_1.setText("fkkkk");
                                   cf.textArea_1.append("fdsfds");
                                 
                       
                                   String hh = realYear+"*"+ realMonth+"*"+ realDay+"*"+ currentYear+"*"+ currentMonth;
                                 // try {Thread.sleep(1000);}catch(Exception gs) {}
                                  //List tpd = CalendarProgram1.getDataByDate(viewingDay);
                                  List tpd = CalendarProgram1.getShiftDataByDate(viewingDay);
                                 
                                  System.out.println(viewingDay +"VIEWING >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> --------->"+ tpd);
                                 
                                    String itemString = " ";
                                  int item_length = 11;
                                  if (tpd !=null){
                                  for(int i=1;i<=tpd.size();i++){
                                   itemString = itemString + tpd.get(i-1)+ " ";
                                
                                   if ( (i % item_length) == 0) {
                                   System.out.println(i+" Appending ----->>"+itemString);
                                        cf.textArea_1.append(" \n "+itemString);    
                                        itemString = " ";
                                   }
                                  }
                                  }else {
                                   System.out.println("  ***************   No Data found             **************"+viewingDay);
                                  }
                                 
                               

                             
                                   cf.setVisible(true);
                                   cf.setAlwaysOnTop(true);
                                   alreadyOpened = true;
                            
                                
                                  frmMain.setVisible(true);
                                  frmMain.setFocusable(false);
                            
                                //  frmMain.getContentPane().add(cf,BorderLayout.WEST);
                                  frmMain.revalidate();
                                    isAlreadyOneClick = false;
                                } else {
                                    isAlreadyOneClick = true;
                                    Timer t = new Timer("doubleclickTimer", false);
                                    t.schedule(new TimerTask() {

                                        @Override
                                        public void run() {
                                            isAlreadyOneClick = false;
                                        }
                                    }, 500);
                                }     
                               
                               
                                    
                        }
                       
                          
                       
                       
                    });

                    //Set bounds
                    //pnlCalendar.setBounds(0, 0, 320, 335);
                    pnlCalendar.setBounds(0, 0, 1000, 900);
                    lblMonth.setBounds(160-lblMonth.getPreferredSize().width/2, 90, 100, 25);
                    lblYear.setBounds(10, 875, 80, 20);
                    cmbYear.setBounds(230, 875, 80, 20);
            //        btnPrev.setBounds(10, 25, 90, 25); // Original
            //        btnNext.setBounds(210, 25, 90, 25);
                    btnPrev.setBounds(10, 90, 90, 25);
                    btnNext.setBounds(210, 90, 90, 25);
                   
                 //   stblCalendar.setBounds(10, 50, 300, 250);
                    stblCalendar.setBounds(10, 120, 980, 740);
                   
                    //Make frame visible
                    frmMain.setResizable(false);
                    frmMain.setVisible(true);
                   
                    //Get real month/year
                    GregorianCalendar cal = new GregorianCalendar(); //Create calendar
                    realDay = cal.get(GregorianCalendar.DAY_OF_MONTH); //Get day
                    realMonth = cal.get(GregorianCalendar.MONTH); //Get month
                    realYear = cal.get(GregorianCalendar.YEAR); //Get year
                    currentMonth = realMonth; //Match month and year
                    currentYear = realYear;
                   
                    //Add headers
                    String[] headers = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"}; //All headers
                    for (int i=0; i<7; i++){
                        mtblCalendar.addColumn(headers[i]);
                    }
                    getAllFac();
                    tblCalendar.getParent().setBackground(tblCalendar.getBackground()); //Set background
                   
                    //No resize/reorder
                    tblCalendar.getTableHeader().setResizingAllowed(false);
                    tblCalendar.getTableHeader().setReorderingAllowed(false);
                   
                    //Single cell selection
                    tblCalendar.setColumnSelectionAllowed(true);
                    tblCalendar.setRowSelectionAllowed(true);
                    tblCalendar.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
                   
                    //Set row/column count
                    tblCalendar.setRowHeight(58);
                    tblCalendar.setRowMargin(1);
                    mtblCalendar.setColumnCount(7);
                    mtblCalendar.setRowCount(6);
                   
                    //Populate table
                    for (int i=realYear-100; i<=realYear+100; i++){
                        cmbYear.addItem(String.valueOf(i));
                    }
                   
                    //Refresh calendar
                    refreshCalendar (realMonth, realYear); //Refresh calendar
                    System.out.println("kjkkkkkkkkkkkkkkkkkkkkkk-->"+tblCalendar.getColumnName(0));
                    }
               
            public static void refreshShiftDetail() {
               String sft = assignment.shift_detail.getSelectedItem()+" ";
              System.out.println("  Selected item at shift_detail --->"+sft);
              String[] arrsft = sft.split(",");
            try {      System.out.println(" string 0"+arrsft[0] + "string 1"+arrsft[1] + "string 2"+arrsft[2]
                + "string 3"+arrsft[3] + "string 4"+arrsft[4]
                  + "string 5"+arrsft[5] );
              if ( arrsft[3].trim().equals("0")) {seven = false;}else seven = true;
              if ( arrsft[4].trim().equals("0")) {three = false;}else three = true;
              if ( arrsft[5].trim().equals("0")) {eleven = false;}else eleven = true;
              sftWhere = arrsft[2];
              String candiTyp = arrsft[1].trim() ;
               popluateCandi("dd",candiTyp);
              setCandi();
              
             
               
              
            }catch(Exception d) {}

            }
                public static void updateShift() {
                
                 String sft_1 = assignment.CandicomboBox.getSelectedItem() + " ";
                 String sft_2 = assignment.candicomboBox_1.getSelectedItem() + " ";
                 String sft_3 = assignment.candicomboBox_2.getSelectedItem() + " ";
                
                 String sft_set =  " set ";
                   sft_set = sft_set + " f_7_3_who = '"+sft_1+"'";
                   sft_set = sft_set + ", f_3_11_who = '"+sft_2+"'";
                   sft_set = sft_set + ", f_11_7_who = '"+sft_3+"'";
                
                
                    String sft_where = " where  Id = ";
                       sft_where = sft_where + " '"+sftWhere +"'";
                   
                 Connection dbConnection = null;
                   ResultSet resultSet = null;
                   ArrayList<String> names = new ArrayList<String>();

                   try {
                       dbConnection = mis.getDatabaseConnection();
                       String query =
                               "update cts_shifts" +
                                sft_set +
                                sft_where ;
                              

                       System.out.println("Sql------>>****"+query);
                        dbConnection.prepareStatement(query).execute();
                        //dbConnection.prepareStatement(query).executeQuery();
                       // dbConnection.commit();

                   } catch (Exception e) {
                  e.printStackTrace();
                     getAllFac();
                     
                   } finally {                          
                   }
                
                }
                public static void refreshAssignmentDate(Set ke) {
                 try {
                 /// Thread.sleep(200);
                 }catch(Exception ee) {}
                 Iterator<String> it = ke.iterator();
            System.out.println(" -------------->>>>"+ke.size());

                  while(it.hasNext()){
                   String item = it.next();
                     System.out.println("Book Date    --------------KKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD"+assignmentStatus);
                        assignment.bookDate.addItem(item);

                  }   
                }
               
                public static void setCandi() {
                    if (!seven) assignment.CandicomboBox.setEnabled(false) ;else  assignment.CandicomboBox.setEnabled(true);
                    if (!three) assignment.candicomboBox_1.setEnabled(false) ;else  assignment.candicomboBox_1.setEnabled(true);
                    if (!eleven) assignment.candicomboBox_2.setEnabled(false) ;else  assignment.candicomboBox_2.setEnabled(true);
                
                }
                public static void refreshAssignment(Set ke) {
                
                  try {
                 /// Thread.sleep(200);
                 }catch(Exception ee) {}
                 Iterator<String> it = ke.iterator();
            System.out.println(" ke size-------------->>>>"+ke.size());

            //assignment.shift_detail.removeAll();
            //System.out.println(" -------------->>>>"+ assignment.shift_detail.list());
            //assignment.shift_detail = new JComboBox();
            JComboBox t_shift_detail = new JComboBox();
            assignment.shift_detail.removeAll();
                  while(it.hasNext()){
                   String item = it.next();
            //        System.out.println("KKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD"+assignmentStatus);
                  //      assignment.bookDate.addItem(item);
               List ks = assignmentStatus.get(item);
              //     System.out.println(item+"LIST    KKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD"+ks);
                 
            //      System.out.println("@@@@@@@@@@@@@@@@@@@@@@@@@"+ks.size());
                      
                   Object[] numbers = ks.toArray();
            //       System.out.println("@@@@@@@@@@@@@@@@@@@@@@@@@"+numbers[1]);
                   String tstring = " ";
                   int itr = ks.size();
                  
                   for (int y=1;y<ks.size();) {
                   
                       System.out.println("*************************"+numbers[y-1]);
                    System.out.println("*************************"+numbers[y]);
                    System.out.println("*************************"+numbers[y+1]);
                    System.out.println("*************************"+numbers[y+2]);
                    System.out.println("*************************"+numbers[y+3]);
                    System.out.println("*************************"+numbers[y+4]);
                    System.out.println("*************************"+numbers[y+5]);
                    System.out.println("*************************"+numbers[y+6]);
                    System.out.println("*************************"+numbers[y+7]);
                    System.out.println("*************************"+numbers[y+8]); 
              
                    String this_item=  numbers[y-1]
                    + " "+numbers[y]
                     +numbers[y+1] +numbers[y+2]
                     +numbers[y+3] +numbers[y+4]
                     +numbers[y+5] +numbers[y+6]
                       ; 

                   

                   
                    if (selectedPeriod != null)   { 
                   if(item.trim() == selectedPeriod.trim()) {   
                    t_shift_detail.addItem(this_item);
                   // assignment.shift_detail.addItem(this_item); 
                  // assignment.shift_detail.setSelectedItem(this_item);
               //     System.out.println(selectedPeriod  + " adding   shift detail: "+ item  + "  <<-adding item->> "+this_item + "  ===>>>"+assignment.shift_detail.getSelectedItem());       
                     
                   }else {
                 // System.out.println( selectedPeriod  + " removing o detail: "+ item +"<<-removing item->> "+this_item  );
                    assignment.shift_detail.removeItem(this_item);
                   }
               
                   }
                y=y+11;         
                   } // end for  
                  //  assignment.whoD.addItem(ks.get(1));
            //       assignment.shift_detail.addItem(ks);

                  
                   
                  }//end while

                  assignment.shift_detail.removeAllItems();
                  for (int t = 0; t < t_shift_detail.getItemCount(); t++)
                  {
                   assignment.shift_detail.addItem(t_shift_detail.getItemAt(t));
                  }

                  setCandi();    
                  System.out.println(  " Selected item  ===>>>"+assignment.shift_detail.getSelectedItem());
                  popluateCandi("dd","DT");
                 
                }
               
                public static java.util.List<String> populateArr(String str) {    
                 java.util.List<String> list = new ArrayList<String>(Arrays.asList(str.split(" , ")));
                 return list;
                }
               
                public static void getFacilities(String str) {
                 java.util.List<String> myList = populateArr(str);
                 System.out.println(str + "insert shifts ---------------------------------->"+myList.size() + " 0 -->"+myList.get(0));
                 Connection dbConnection = null;
                   ResultSet resultSet = null;
                   ArrayList<String> names = new ArrayList<String>();

                   try {
                       dbConnection = mis.getDatabaseConnection();
                       String query =
                               " select * from cts_cus " +
                                " ";
              System.out.println("Sql- get facilitys----->>****"+query);
                     resultSet =   dbConnection.prepareStatement(query).executeQuery();
                     //   dbConnection.commit();
                     while (resultSet.next()) {
                         shifts.comboBox_4.addItem(resultSet.getString(2));
                         shifts.comboBox_5.addItem(resultSet.getString(2));
                        
                     }

                   } catch (Exception e) {
                     e.printStackTrace();
                   } finally {                          
                   }
                }   

                public static String getCandiInfo() {
               
                  String str =  candipanel.fname.getText();
                       str = str  + " , " + candipanel.lname.getText() + " , "+candipanel.candiTypecomboBox.getSelectedItem() ;
                  return str;
                }
               
                public static void insertCandi() {
                 System.out.println(" inserting candidate ");
               
                    String str = getCandiInfo();
                
                 java.util.List<String> myList = populateArr(str);
                 System.out.println(str + " insert shifts ---------------------------------->"+myList.size() + " 0 -->"+myList.get(0));
                 Connection dbConnection = null;
                   ResultSet resultSet = null;
                   ArrayList<String> names = new ArrayList<String>();

                   try {
                       dbConnection = mis.getDatabaseConnection();
                       String query =
                               "insert into cts_candi" +
                               " values ( '" + myList.get(0)+"' , '"+ myList.get(1)+"','"+   myList.get(2)  +"'  )";

                       System.out.println("Sql------>>****"+query);
                        dbConnection.prepareStatement(query).executeQuery();
                        dbConnection.commit();

                   } catch (Exception e) {
                  e.printStackTrace();
                     getAllFac();
                     
                   } finally {                          
                   }
                
                }
                public static void insertShifts(String str) {
                 java.util.List<String> myList = populateArr(str);
                 System.out.println(str + " insert shifts ---------------------------------->"+myList.size() + " 0 -->"+myList.get(0));
                 Connection dbConnection = null;
                   ResultSet resultSet = null;
                   ArrayList<String> names = new ArrayList<String>();

                   try {
                       dbConnection = mis.getDatabaseConnection();
                      
                       int S = 0;
                       int T = 0;
                       int E = 0;
                       try {S = Integer.parseInt(myList.get(2).trim());}catch(Exception e) {};
                       try {T = Integer.parseInt(myList.get(3).trim());}catch(Exception e) {};
                       try {E = Integer.parseInt(myList.get(4).trim());}catch(Exception e) {};
                                 
                       int B = 0;
                       if (S>T && S> E) {
                        B = S;
                       }else if ( T > E) {
                        B = T;
                       }else B = E;
              
                      
                       System.out.println(" Inserting shifts --------%%%%%%%%%%%%%%%%%%%%%%%%%%%%%--------------->"+B);
                       for (int i=0;i< B;i++) {
                        int Si,Ti,Ei = 0;
                        if (S != 0){S = S-1; Si =1;}else Si=0;
                        if (T != 0){T = T-1; Ti =1;}else Ti=0;
                        if (E != 0){E = E-1; Ei =1;}else Ei=0;
                       
                       String query =
                               "insert into cts_shifts(day,fac_name,candi_type,f_7_3,f_3_11,f_11_7)" +
                               " values ( '" + myList.get(5)+"', '"+ myList.get(0)+"','"+myList.get(1)+"','"+Si+"','"+Ti+ "'"
                               +" , '"+Ei+ "'"+" )";

                       System.out.println("Sql------>>****"+query);
                     //   dbConnection.prepareStatement(query).executeQuery();
                        dbConnection.createStatement().execute(query);
                       }
                       // dbConnection.commit();

                   } catch (Exception e) {
                  e.printStackTrace();
                     getAllFac();
                     
                   } finally {                          
                   }
                   getAssignmentStatus();
                 //  refreshShiftDetail();
                  
                }   

               
               
               
               
                public static List getShiftDataByDate(String dt) {    
                 //System.out.println("DDDDDDDDDDDDDDDDDAAAAAAAAAAAAAAATE____________>"+dt);
                // dt = "2017-12-11";
                 String myd = " ";
                
                  List mydlist = assignmentStatus.get(dt);

              ///System.out.println(" hm data"+hm);
             
                // System.out.println(" fExiting value --->  getDataByDate -->"+dt + "   data is -->");
                
                try {
                 for ( int j=0;j<mydlist.size();j++) {
                  //System.out.print(" "+ mydlist.get(j));
                  if ( (j != 0) && ((j+1) % daySize == 0)) {
                  // System.out.println();
                  }
                 }
                }catch(Exception kk) {
                 ///System.out.println(" kkk --->"+kk);
                }

                 return mydlist;
                }
               
                public static void getAssignmentStatus() {
                 Connection dbConnection = null;
                    ResultSet resultSet = null;
               try {     
                 dbConnection = mis.getDatabaseConnection();
                      String query =
                      //"select bday,bfac_name,bcandi_type,day,fac_name,canditype,booked,whod from assignment_status order by 1,2,3" ;
                      "select day,fac_name,candi_type,Id,f_7_3,f_3_11,f_11_7,f_7_3_who,f_3_11_who,f_7_3_ti,f_7_3_to "
                      + "from cts_shifts order by 1,2,3" ;
                        System.out.println("Sql getAssignmentStatus------>>****"+query);     
                   ResultSet rs = dbConnection.prepareStatement(query).executeQuery();
                   List<String> values = new ArrayList<String>();
               
                   String key1 = " ";
                
                   //values.add("Value 1");
                   // values.add("Value 2");
                 //hm.put("Key1", values);

                 // to get the arraylist
                // System.out.println(hm.get("key1"));
                
                
                 String predat = " ";
                 boolean firsttime = true;
                 String dat ="";
                String fac = "" ;// rs.getString(2);
                String candi = "";//rs.getString(3);            
                String  s7 = "";//rs.getString(4);
               String  s11 = "";//rs.getString(4);
              String  s3 = "";//rs.getString(4);
              String f1 = "";
              String f2 = "";
              String f3 = "";
              String f4 = "";
              String f5 = "";
              String f6 = "";
             
             
                 while (rs.next()) {
                      dat = rs.getString(1);
                      fac = rs.getString(2) +" , ";
                      candi = rs.getString(3) +" , ";
                      s7 = rs.getString(4) +" , ";
                      s3 = rs.getString(5)+" , ";
                      s11 = rs.getString(6)+" , ";
                   f1 = rs.getString(7)+" , ";
                 f2 = rs.getString(8)+" , ";
                  f3 = rs.getString(9);
                 f4 = rs.getString(10);
                 /*  f5 = rs.getString(11);
                  f6 = rs.getString(12);
                 
               */      
                  //  AllShifts.put(dat+fac +","+candi+",",fac +","+candi+","+s7);
                         // shifts.comboBox_5.addItem(resultSet.getString(2));
                  // System.out.println(AllShifts.size()+" Hastable ----------->"+AllShifts);
                //   System.out.println("Is -->>"+dat +" = "+ predat);  
                   if(!dat.equals(predat)) {
                 //   System.out.println ("   Key TOKEN IS CHANGED");
                    predat = dat;        
                    if(!firsttime) {
                     assignmentStatus.put(key1, values);          
              
                 //       System.out.println(key1+"<--key1  values"+values);   
                       
                         values = new ArrayList<String>();
                           key1 = dat;       
                         values.add(fac);
                         values.add(candi);
                         values.add(s7);
                     values.add(s3);
                    values.add(s11);
                  
                   
                   values.add(f1);
                   values.add(f2);
                   values.add(f3);
                   values.add(f4);
                   values.add(f5);
                   values.add(f6);
                   
                      
                       }else {
                       key1 = dat;       
                       values.add(fac);
                       values.add(candi);
                       values.add(s7);
                    values.add(s3);
                    values.add(s11);
                values.add(f1);
                   values.add(f2);
                   values.add(f3);
                   values.add(f4);
                   values.add(f5);
                   values.add(f6);
                  
                //    System.out.println("This is FIRST time ----> so inserting Map key1"+key1);
                        firsttime = false;
                       
                       }
                    }else {
                    key1 = dat;

                   values.add(fac);
                   values.add(candi);
                 values.add(s7);
                values.add(s3);
                    values.add(s11);
                   values.add(f1);
                   values.add(f2);
                   values.add(f3);
                   values.add(f4);
                   values.add(f5);
                   values.add(f6);             
                 //         System.out.println (key1+" NOT CHANGED    TOKEN  "+candi);                   
                    }
                      }      
                   //Last one
                 assignmentStatus.put(key1, values);            
               //     System.out.println(key1+"<--key1  values"+values); 
              //     System.out.println( "   My Hastable ----------->"+assignmentStatus);   
            //    System.out.println(assignmentStatus.keySet());
                   Set se = assignmentStatus.keySet();
                
                   for (int i=0;i<assignmentStatus.size();i++) {
                  //System.out.println("Key Set ----->"+assignmentStatus.keySet()); 
                 
                   }
                  
                 // getDataByDate("DDDDDDD");
                  }catch(Exception ex) {         
                   System.out.println("ex)"+ex); ex.printStackTrace();         
                  }
            }

               
               
                public static void getAllFac() {
                    Connection dbConnection = null;
                       ResultSet resultSet = null;
                  try {     
                    dbConnection = mis.getDatabaseConnection();
                         String query =
                                " select day,fac_name,candi_type, sum( f_7_3) as f_7_3,  sum(f_3_11) as f_3_11 ,  sum(f_11_7) as f_11_7 "
                               +" , f1, f2, f3,  f4,  f5,  f6,  f7,  f8, f9,  f10 "
            +" from mytest_vw "
            + " group by  day,fac_name,candi_type , f1, f2, f3,  f4,  f5,  f6,  f7,  f8, f9,  f10"
            +" order by day "
                              ;
               System.out.println("Sql------>>****"+query);
                    
                      ResultSet rs = dbConnection.prepareStatement(query).executeQuery();
                //    AllShifts = new HashMap();
                  

             

                    List<String> values = new ArrayList<String>();
                   String key1 = " ";
                   
                    //values.add("Value 1");
                   // values.add("Value 2");
                    //hm.put("Key1", values);

                    // to get the arraylist
               /////////////////////////  System.out.println("*****************************************"+hm.get("key1"));
                   
                   
                    String predat = " ";
                    boolean firsttime = true;
                    String dat ="";
                 String fac = "" ;// rs.getString(2);
                 String candi = "";//rs.getString(3);            
                 String  s7 = "";//rs.getString(4);
                String  s11 = "";//rs.getString(4);
               String  s3 = "";//rs.getString(4);
              String f1 = "";
              String f2 = "";
              String f3 = "";
              String f4 = "";
              String f5 = "";
              String f6 = "";
             
              
                    while (rs.next()) {
                         dat = rs.getString(1);
                         fac = rs.getString(2);
                         candi = rs.getString(3);
                         s7 = rs.getString(4);
                         s3 = rs.getString(5);
                         s11 = rs.getString(6);
                      f1 = rs.getString(7);
                     f2 = rs.getString(8);
                     f3 = rs.getString(9);
                     f4 = rs.getString(10);
                     f5 = rs.getString(11);
                     f6 = rs.getString(12);
                    
                        
                     //  AllShifts.put(dat+fac +","+candi+",",fac +","+candi+","+s7);
                            // shifts.comboBox_5.addItem(resultSet.getString(2));
                     // System.out.println(AllShifts.size()+" Hastable ----------->"+AllShifts);
                         System.out.println("Is -->>"+dat +" = "+ predat);  

                         if(!dat.equals(predat)) {
                       System.out.println ("   Key TOKEN IS CHANGED");
                       predat = dat;        
                       if(!firsttime) {
                       hmShifts.put(key1, values);          
                 
                           System.out.println(key1+"<--key1  values"+values);                  
                           values = new ArrayList<String>();
                            key1 = dat;       
                            values.add(fac);
                            values.add(candi);
                      //   values.add("S7");
                        values.add(s7);
                              values.add(s3);
                            values.add(s11);
                            values.add(f1);
                            values.add(f2);
                            values.add(f3);
                            values.add(f4);
                            values.add(f5);
                            values.add(f6);
                          }else {
                            key1 = dat;       
                            values.add(fac);
                            values.add(candi);
                         //          values.add("S7");
                             values.add(s7);
                            values.add(s3);
                            values.add(s11);
                            values.add(f1);
                            values.add(f2);
                            values.add(f3);
                            values.add(f4);
                            values.add(f5);
                            values.add(f6);       
                            System.out.println("This is FIRST time ----> so inserting Map key1"+key1);
                           firsttime = false;
                          }
                       }else {
                       key1 = dat;

                      values.add(fac);
                      values.add(candi);
                 //   values.add("S7");
                      values.add(s7);
                   values.add(s3);
                    values.add(s11);
                   values.add(f1);
                      values.add(f2);
                      values.add(f3);
                      values.add(f4);
                      values.add(f5);
                      values.add(f6);
                           
                             System.out.println (key1+" NOT CHANGED    TOKEN  "+candi);           
                      
                       }
                     
                     
                         }      
                      //Last one
                    hmShifts.put(key1, values);          
             
                    System.out.println(key1+"<--key1  values"+values); 
                   
                   
                   
                      System.out.println( "   My Hastable ----------->"+hmShifts);   
                  
                System.out.println("hm"+hmShifts.keySet());
                   Set se = hmShifts.keySet();
                  
                 ////////////////////////  assignment.bookDate.add
                  /*
                      for (int i=0;i<hm.size();i++) {
                     System.out.println(hm.keySet());        
                      }
                      */         
                    // getDataByDate("DDDDDDD");
                     }catch(Exception ex) {         
                      System.out.println("ex)"+ex); ex.printStackTrace();         
                   }
                }
               
               

               
                public static List getDataByDate(String dt) {    
                 //System.out.println("DDDDDDDDDDDDDDDDDAAAAAAAAAAAAAAATE____________>"+dt);
                // dt = "2017-12-11";
                 String myd = " ";
                
                  List mydlist = hmShifts.get(dt);

              ///System.out.println(" hm data"+hm);
             
                // System.out.println(" fExiting value --->  getDataByDate -->"+dt + "   data is -->");
                
                try {
                 for ( int j=0;j<mydlist.size();j++) {
                  //System.out.print(" "+ mydlist.get(j));
                  if ( (j != 0) && ((j+1) % daySize == 0)) {
                  // System.out.println();
                  }
                 }
                }catch(Exception kk) {
                 ///System.out.println(" kkk --->"+kk);
                }

                 return mydlist;
                }
               
               
                public static void popluateCandi(String zip,String type) {
                
                 String mtype = type;
                 Connection dbConnection = null;
                   ResultSet resultSet = null;
                   ArrayList<String> names = new ArrayList<String>();
                   try {
                       dbConnection = mis.getDatabaseConnection();
                       String query =
                               "SELECT fname + ' , ' + lname " +
                               "FROM cts_candi " +
                               "where type = '"+mtype+"'";
            ///          System.out.println(" popluateCandi ------------------------------------------>"+mtype);
                       resultSet = dbConnection.prepareStatement(query).executeQuery();

                       assignment.CandicomboBox.removeAllItems();
                       assignment.candicomboBox_1.removeAllItems();
                       assignment.candicomboBox_2.removeAllItems();
                      
            //System.out.println(" CandicoboBox emptied ---->"+assignment.CandicomboBox.getItemCount());
                       while (resultSet.next()) {
                       String rslt =  resultSet.getString(1)+"";
                        assignment.CandicomboBox.addItem(rslt);
                        assignment.candicomboBox_1.addItem(rslt);
                        assignment.candicomboBox_2.addItem(rslt);
                        //   names.add(resultSet.getString(1));
                        //    System.out.println(" name--> "+resultSet.getString(1)+"");
                      //      System.out.println(" CandicoboBox Item count now ---->"+assignment.CandicomboBox.getItemCount());
                           // break;
                       }
                   } catch (Exception e) {
                        e.printStackTrace();
                   } finally {                          
                   }    
                
                }
               
               
                public static void insertCust(String str) {
                 java.util.List<String> myList = populateArr(str);
                 System.out.println(str + ":List items ---------------------------------->"+myList.size() + " 0 -->"+myList.get(0));
                 Connection dbConnection = null;
                   ResultSet resultSet = null;
                   ArrayList<String> names = new ArrayList<String>();

                   try {
                       dbConnection = mis.getDatabaseConnection();
                       String query =
                               "insert into cts_cus" +
                               " values ('20000', '" + myList.get(0)+"','"+myList.get(1)+"'"+
                               " )";

                        dbConnection.prepareStatement(query).executeQuery();
                        dbConnection.commit();

                   } catch (Exception e) {
                     e.printStackTrace();
                   } finally {                          
                   }
                }   
                public static void getCalInfo () {
                 //insertCust("Rav dd , Kaur fs ");
                // populateArr("Harinder, Singh");
                    Connection dbConnection = null;
                       ResultSet resultSet = null;
                       ArrayList<String> names = new ArrayList<String>();
                       try {
                           dbConnection = mis.getDatabaseConnection();
                           String query =
                                   "SELECT first_name + ' , ' + last_name " +
                                   "FROM cts_cus " +
                                   "ORDER BY last_name";

                           resultSet = dbConnection.prepareStatement(query).executeQuery();
                           while (resultSet.next()) {
                               names.add(resultSet.getString(1));
                               System.out.println(" name--> "+names.get(0));
                               break;
                           }
                       } catch (Exception e) {
            //               e.printStackTrace();
                       } finally {                          
                       }        
                }       
                public static String getCalText(int year, int month, int day ) {
                 String str = " ";
                 str = mytext[0][0][0];
                 return str ;
                }
                public static void refreshCalendar(int month, int year){
                    //Variables
                    String[] months =  {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"};
                    int nod, som; //Number Of Days, Start Of Month
                   
                    //Allow/disallow buttons
                    btnPrev.setEnabled(true);
                    btnNext.setEnabled(true);
                    if (month == 0 && year <= realYear-10){btnPrev.setEnabled(false);} //Too early
                    if (month == 11 && year >= realYear+100){btnNext.setEnabled(false);} //Too late
                    lblMonth.setText(months[month]); //Refresh the month label (at the top)
                    lblMonth.setBounds(160-lblMonth.getPreferredSize().width/2, 90, 180, 25); //Re-align label with calendar
                    cmbYear.setSelectedItem(String.valueOf(year)); //Select the correct year in the combo box
                   
                    //Clear table
                    for (int i=0; i<6; i++){
                        for (int j=0; j<7; j++){
                            mtblCalendar.setValueAt(null, i, j);
                        }
                    }
                   
                    //Get first day of month and number of days
                    GregorianCalendar cal = new GregorianCalendar(year, month, 1);
                    nod = cal.getActualMaximum(GregorianCalendar.DAY_OF_MONTH);
                    som = cal.get(GregorianCalendar.DAY_OF_WEEK);
                   
                    //Draw calendar
                    for (int i=1; i<=nod; i++){
                        int row = new Integer((i+som-2)/7);
                        int column  =  (i+som-2)%7;
                //        mtblCalendar.setValueAt(i+"\n\n sS" +"\t"+"html><div style=\"text-align:center\">Math fdsfsdafdsa,<br>Class1</div></html>"
                 //         + " \n jj", row, column);
                        JPanel jp = new JPanel();
                         jp.setBounds(0, 10, 10, 10);
                        mtblCalendar.setValueAt( Integer.toString(i), row, column);

                     
                        //   mtblCalendar.setValueAt(i, row, column);
                        //  System.out.println("year :  "+year+" month -->"+month+" : row -->"+row +" : column-->"+column +"  i-->"+i  );
                       
                    }       
                   
                   
                    //Apply renderers
            //       tblCalendar.setDefaultRenderer(tblCalendar.getColumnClass(0), new PlusMinusCellRenderer());
                 //   tblCalendar.setDefaultRenderer(tblCalendar.getColumnClass(0), new tblCalendarRenderer());
                    tblCalendar.getColumn("Mon").setCellRenderer(new TextAreaRenderer("SF"));
                    tblCalendar.getColumn("Tue").setCellRenderer(new TextAreaRenderer("SF"));
                    tblCalendar.getColumn("Wed").setCellRenderer(new TextAreaRenderer("SF"));
                    tblCalendar.getColumn("Thu").setCellRenderer(new TextAreaRenderer("SF"));
                    tblCalendar.getColumn("Fri").setCellRenderer(new TextAreaRenderer("SF"));
                    tblCalendar.getColumn("Sat").setCellRenderer(new TextAreaRenderer("SF"));
                    tblCalendar.getColumn("Sun").setCellRenderer(new TextAreaRenderer("SF"));
                   
                  //  tblCalendar.getColumn("Mon").setCellEditor(new TextAreaEditor("FS"));
                  //  tblCalendar.getColumn("Mon").setCellEditor(new TextAreaEditor("F2"));
                   
                   // TextAreaEditor tx = new TextAreaEditor("F3");
                      
                    Label lb = new Label("DFDF");
                //    tx.get(lb);
                   
                //    tblCalendar.getColumn("Mon").setCellEditor(new TextAreaEditor("F3"));
                   
                    
                   
                    System.out.println("-------------------"+tblCalendar.getCellRenderer(0, 1));
                    tblCalendar.setRowHeight(120);
                    tblCalendar.setRowMargin(1);
                    tblCalendar.revalidate();
                }
                /*
                static class PlusMinusCellRenderer extends JPanel implements TableCellRenderer {
                    public Component getTableCellRendererComponent(
                                        final JTable table, Object value,
                                        boolean isSelected, boolean hasFocus,
                                        int row, int column) {
                            this.add( new JTextField( value.toString()  ) );
                            this.add( new JButton("+"));
                            this.add( new JButton("-"));
                            return this;
                    }
            }
                */
                static class tblCalendarRenderer extends   DefaultTableCellRenderer{
                
                
                    public Component getTableCellRendererComponent (JTable table, Object value, boolean selected, boolean focused, int row, int column){
              
                        value = value + " \r DD";
                         
                     super.getTableCellRendererComponent(table, value, selected, focused, row, column);   
                     
                     
                        ///    String toReturn = "<html><b>" + (String)value + "</b></html>"; 
                     System.out.println(" 3 Exiting "+value);
                  System.exit(9);
                    
                      
                      //  table.setValueAt("Harin", row, column);
                 //   javax.swing.border.Border padding = BorderFactory.createEmptyBorder(0, 10, 0, 10);

                 //      Component cell = getTableCellRendererComponent(
                   //          table, value, selected, focused, row, column);
                       
                    ///    String valueD = (String)value;
                       
                      //  table.getColumn("Notes").setCellRenderer(new TableCellRenderer());
                       
                      //  textarea = new JTextArea(2,20);
                      //  table.add(textarea);
                    //    textarea.setLineWrap(true);
                  //      textarea.setWrapStyleWord(true);

               //          textarea.setText(valueD);
            //             textarea.setWrapStyleWord(true);
                //         textarea.setLineWrap(true);
                //         DefaultCaret caret = (DefaultCaret) textarea.getCaret();
               //          caret.setUpdatePolicy(DefaultCaret.NEVER_UPDATE);
                    
                       // value = "{<html><i><u><b>HTML</b></u></i></html>" ;
                      
                  //       setBorder(BorderFactory.createCompoundBorder(getBorder(), padding));
                  //       this.add(new JLabel("SSD"));
                        
                        if (selected) {
                             this.setBackground(Color.lightGray);
                           }

                        if (column == 0 || column == 6){ //Week-end
                                setBackground(new Color(255, 220, 220));
                               // table.setValueAt("SSS", 0, 2);
                        }
                        else{ //Week
                                setBackground(new Color(255, 255, 255));
                        }
                        if (value != null){
                         try {
                            if (Integer.parseInt(value.toString()) == realDay && currentMonth == realMonth && currentYear == realYear){
                             //Today
                         //      setBackground(new Color(220, 220, 255));
                                 setBackground(new Color(220, 220, 255));
                                }
                         }catch(Exception ee) {
                         
                         
                         }
                        
                        } {
                         
                        }
                      
                        if (selected) {
                     setBackground(Color.lightGray);
                         }
                       
                     //   setBorder(null);
                     //   setForeground(Color.black);

                       
                        if (selected) {
                           // cell.getCsetBackground(Color.OPAQUE); //(and perhaps other cells) are selected
                        }

                        if (focused) {
                            // this cell is the anchor and the table has the focus
                        }

                        // Configure the component with the specified value
                      //  setText(value.toString());

                        // Set tool tip if desired
                      //  setToolTipText((String)value);

                        // Since the renderer is a component, return itself
                       validate();
                                     return this;
                   //     return new JLabel(toReturn); 

                    } 
                }
               
               
                static class btnPrev_Action implements ActionListener{
                    public void actionPerformed (ActionEvent e){
                        if (currentMonth == 0){ //Back one year
                            currentMonth = 11;
                            currentYear -= 1;
                        }
                        else{ //Back one month
                            currentMonth -= 1;
                        }
                        refreshCalendar(currentMonth, currentYear);
                    }
                }
               
                static class btnNext_Action implements ActionListener{
                    public void actionPerformed (ActionEvent e){
                        if (currentMonth == 11){ //Foward one year
                            currentMonth = 0;
                            currentYear += 1;
                        }
                        else{ //Foward one month
                            currentMonth += 1;
                        }
                        refreshCalendar(currentMonth, currentYear);
                    }
                }
                static class cmbYear_Action implements ActionListener{
                    public void actionPerformed (ActionEvent e){
                        if (cmbYear.getSelectedItem() != null){
                            String b = cmbYear.getSelectedItem().toString();
                            currentYear = Integer.parseInt(b);
                            refreshCalendar(currentMonth, currentYear);
                        }
                    }
                }
            }

            class MiscDatabaseTasks {

                private static Map<String, String> config = null;
                //creates the connection string
                private static Map<String, String> getDatabaseConfig() {
                    if (config == null) {
                        Map<String, String> props = new HashMap<String, String>();
                        props.put("database.class", "net.sourceforge.jtds.jdbc.Driver");
                        props.put("database.url",
                                "jdbc:jtds:sqlserver://PSCWS10049;databaseName=cts_dashboard_dev");
                        props.put("database.username", "cts_dashboard_user");
                        props.put("database.password", "Nomura_123");
                        config = Collections.unmodifiableMap(props);
                    }
                    return config;
                }
                //Connects to the database
                public static Connection getDatabaseConnection() throws SQLException, ClassNotFoundException {
                    Map<String, String> dbConfig = getDatabaseConfig();
                    Class.forName(dbConfig.get("database.class"));
                    return DriverManager.getConnection(dbConfig.get("database.url"),
                            dbConfig.get("database.username"),
                            dbConfig.get("database.password"));
                }
               
                //Finds the parent apps
              
               
                //Receives the name and finds the employee ID based on it
                public static Integer getEmployeeIdByName(String name) throws SQLException, ClassNotFoundException {
                    Connection dbConnection = null;
                    ResultSet resultSet = null;
                    PreparedStatement ps = null;

                    try {
                        dbConnection = getDatabaseConnection();
                        String query =
                                "SELECT user_id " +
                                "FROM CTS_TUser " +
                                "WHERE first_name + ' '  + last_name = ?";

                        ps = dbConnection.prepareStatement(query);
                        ps.setString(1, name);
                        resultSet = ps.executeQuery();
                        if (resultSet.next()) {
                            return resultSet.getInt(1);
                        }
                    } finally {
                        if (dbConnection != null) {
                            dbConnection.close();
                        }
                        if (resultSet != null) {
                            resultSet.close();
                        }
                        if (ps != null) {
                            ps.close();
                        }
                    }
                    return null;
                }
                //Returns a list of all of the employee names
                public static ArrayList<String> getEmployeeNames() throws SQLException, ClassNotFoundException {
                    Connection dbConnection = null;
                    ResultSet resultSet = null;
                    ArrayList<String> names = new ArrayList<String>();

                    try {
                        dbConnection = getDatabaseConnection();
                        String query =
                                "SELECT first_name + ' ' + last_name " +
                                "FROM CTS_TUser " +
                                "ORDER BY last_name";

                        resultSet = dbConnection.prepareStatement(query).executeQuery();
                        while (resultSet.next()) {
                            names.add(resultSet.getString(1));
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                    } finally {
                        if (dbConnection != null) {
                            dbConnection.close();
                        }
                        if (resultSet != null) {
                            resultSet.close();
                        }
                    }
                    return names;
                }

                public static ArrayList<String> getBusinessLines() throws SQLException, ClassNotFoundException {
                    Connection dbConnection = null;
                    ResultSet resultSet = null;
                    ArrayList<String> names = new ArrayList<String>();

                    try {
                        dbConnection = getDatabaseConnection();
                        String query =
                                "SELECT * FROM CTS_TBusiness order by 2";

                        resultSet = dbConnection.prepareStatement(query).executeQuery();
                        while (resultSet.next()) {
                            names.add(resultSet.getString(1));
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                    } finally {
                        if (dbConnection != null) {
                            dbConnection.close();
                        }
                        if (resultSet != null) {
                            resultSet.close();
                        }
                    }
                    return names;
                }
            }

            • 3. Re: Code throwing Null exceptoin
              hphanjra-JavaNet

              //package FinCal;

               

              import java.awt.BorderLayout;

              import java.awt.FlowLayout;

               

              import javax.swing.JButton;

              import javax.swing.JDialog;

              import javax.swing.JPanel;

              import javax.swing.border.EmptyBorder;

               

              public class DayDetail extends JDialog {

               

                              private
              final JPanel contentPanel = new JPanel();

               

                              /**

                               * Launch the application.

                               */

                              public
              static void main(String[] args) {

                                              try
              {

                                                              DayDetail
              dialog = new DayDetail();

                                                              dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);

                                                              dialog.setVisible(true);

                                              }
              catch (Exception e) {

                                                              e.printStackTrace();

                                              }

                              }

               

                              /**

                               * Create the dialog.

                               */

                              public
              DayDetail() {

                                              setBounds(100,
              100, 450, 300);

                                              getContentPane().setLayout(new
              BorderLayout());

                                              contentPanel.setLayout(new
              FlowLayout());

                                              contentPanel.setBorder(new
              EmptyBorder(5, 5, 5, 5));

                                              getContentPane().add(contentPanel,
              BorderLayout.CENTER);

                                              {

                                                              JPanel
              buttonPane = new JPanel();

                                                              buttonPane.setLayout(new
              FlowLayout(FlowLayout.RIGHT));

                                                              getContentPane().add(buttonPane,
              BorderLayout.SOUTH);

                                                              {

                                                                              JButton
              okButton = new JButton("OK");

                                                                              okButton.setActionCommand("OK");

                                                                              buttonPane.add(okButton);

                                                                              getRootPane().setDefaultButton(okButton);

                                                              }

                                                              {

                                                                              JButton
              cancelButton = new JButton("Cancel");

                                                                              cancelButton.setActionCommand("Cancel");

                                                                              buttonPane.add(cancelButton);

                                                              }

                                              }

                              }

               

              }

               

              package FinCal;

               

              import javax.swing.JPanel;

              import javax.swing.border.CompoundBorder;

               

              import java.awt.Rectangle;

               

              import javax.swing.JLabel;

              import javax.swing.JComboBox;

              import javax.swing.JTextField;

              import javax.swing.border.LineBorder;

               

              import java.awt.Color;

              import java.awt.event.ActionListener;

              import java.awt.event.ActionEvent;

              import java.awt.event.ItemEvent;

              import java.awt.event.ItemListener;

              import java.awt.Choice;

              import javax.swing.JButton;

               

              public class Assignment extends JPanel {

                              JLabel
              lblAssignSomeone = new JLabel("Assign Candidate");

                              JLabel
              lblDate = new JLabel("Date");

                              private
              JTextField comments;

                              JComboBox
              bookDate = new JComboBox();

                              JLabel
              lblComments = new JLabel("Comments");

                              JComboBox
              shift_detail = new JComboBox();

                              JButton
              btnSave = new JButton("Save");

                             

                             

                   static String
              assignSelectedDate =  " ";

                               static    JComboBox
              CandicomboBox = new JComboBox();

                                JComboBox candicomboBox_1 = new JComboBox();

                                 JComboBox candicomboBox_2 = new JComboBox();

                             

                              /**

                               * Create the panel.

                               */

                              public
              Assignment() {

                                              setBounds(new
              Rectangle(100, 100, 700, 700));

                                              setBorder(new
              LineBorder(Color.BLUE, 2));

                                              setLayout(null);

                                             

                                              lblAssignSomeone.setBounds(416,
              11, 108, 24);

                                              add(lblAssignSomeone);

                                             

                                              lblDate.setBounds(24,
              46, 46, 14);

                                              add(lblDate);

                                              bookDate.addActionListener(new
              ActionListener() {

                                                              public
              void actionPerformed(ActionEvent arg0) {

                                                                             

                                                                              System.out.println("  Action listner for book date
              -------------------->");

                                                                             

                                                              }

                                              });

                             

                                              /*

                                              bookDate.addItemListener(new
              ItemListener() {

                                                              public
              void itemStateChanged(ItemEvent arg0) {

                                              System.out.println("
              ss Select ITem is ---->"+bookDate.getSelectedItem());                       

                                              assignSelectedDate
              = (String)shift_detail.getSelectedItem();

                                                              }

                                              });

               

              */                          

                                              bookDate.setBounds(26,
              69, 94, 20);

                                              add(bookDate);

                                             

                                              comments
              = new JTextField();

                                              comments.setText("This
              is a commentsss");

                                              comments.setBounds(455,
              252, 164, 20);

                                              add(comments);

                                              comments.setColumns(10);

                                             

                                              lblComments.setBounds(386,
              255, 59, 14);

                                              add(lblComments);

                                              shift_detail.addActionListener(new
              ActionListener() {

                                                              public
              void actionPerformed(ActionEvent arg0) {

                                                              //            System.out.println("
              Shift_detail pressed ");

                                                              }

                                              });

                                             

                                              shift_detail.setBounds(130,
              69, 407, 20);

                                              /*

                                                shift_detail.addItemListener(new
              ItemListener() {

                                                      public void itemStateChanged(ItemEvent
              arg0) {

                                                          //Do Something

                                                              System.out.println("item
              changed Selected ITem is ---->"+shift_detail.getSelectedItem());

                                                             

                                                      }

                                                  });

                                                */

                                               

                                              add(shift_detail);

                                             

                                              Choice
              choice = new Choice();

                                              choice.setBounds(416,
              355, 121, 20);

                                              add(choice);

                                              CandicomboBox.addActionListener(new
              ActionListener() {

                                                              public
              void actionPerformed(ActionEvent arg0) {

                                                              //            System.out.println("Selected
              Candi");

                                                              }

                                              });

                                             

               

                                              CandicomboBox.setBounds(130,
              140, 94, 20);

                                              add(CandicomboBox);

                                             

                                             

                                              btnSave.addActionListener(new
              ActionListener() {

                                                              public
              void actionPerformed(ActionEvent arg0) {

                                                                             

                                                              }

                                              });

                                             

                                             

                                              btnSave.setBounds(100,
              355, 89, 23);

                                              add(btnSave);

                                              candicomboBox_1.setBounds(234,
              140, 94, 20);

                                             

                                              add(candicomboBox_1);

                                              candicomboBox_2.setBounds(338,
              140, 94, 20);

                                             

                                              add(candicomboBox_2);

                                             

                              }

              }

               

              package FinCal;

               

              /*

              * select * from
              cts_cus

              select * from cts_shifts

               

               

               

              drop table cts_cus

              go

              CREATE TABLE [dbo].[cts_cus](

                              [day]
              [varchar](10) NULL,

                              [fac_name]
              [varchar](20) NULL,

                              [last_name]
              [varchar](10) NULL

              ) ON [PRIMARY]

               

               

              drop table cts_shifts

              go

              CREATE TABLE
              [dbo].[cts_shifts](

                              [day]
              [varchar](20) primary key,

                              [fac_name]
              [varchar](20) NULL,

                              [candi_type]
              [varchar](10) NULL,

                              [f_7_3]
              [varchar](10) NULL,

                              [f_3_11]
              [varchar](10) NULL,

                              [f_11_7]
              [varchar](10) NULL

              )

               

               

              */

              import java.awt.Color;

              import java.awt.Rectangle;

               

              import javax.swing.JPanel;

              import javax.swing.JButton;

              import javax.swing.UIManager;

              import javax.swing.border.TitledBorder;

               

              import java.awt.event.MouseAdapter;

              import java.awt.event.MouseEvent;

               

              import javax.swing.JLabel;

              import javax.swing.JComboBox;

              import javax.swing.DefaultComboBoxModel;

              import javax.swing.JSpinner;

              import javax.swing.SpinnerDateModel;

               

              import com.sun.org.apache.bcel.internal.generic.INSTANCEOF;

               

              import java.text.DateFormat;

              import java.text.SimpleDateFormat;

              import java.util.Date;

              import java.util.Calendar;

              import java.beans.PropertyChangeListener;

              import java.beans.PropertyChangeEvent;

              import java.awt.event.InputMethodListener;

              import java.awt.event.InputMethodEvent;

              import javax.swing.event.ChangeListener;

              import javax.swing.event.ChangeEvent;

               

              public class Shifts extends JPanel {

                              JButton
              btnNewButton = new JButton("Save");

                              JComboBox
              comboBox_4 = new JComboBox();

                              DateFormat
              dateFormat = new SimpleDateFormat("yyyy-MM-dd");

                              String
              ystr = dateFormat.format(new Date ());

                              ComboCount
              combcnt = new ComboCount();

                              JComboBox
              comboBox_5 = new JComboBox();

                             

                             

                             

                             

                              /**

                               * Create the panel.

                               */

                              public
              Shifts() {

                                              setLayout(null);

                                             

                                              setEnabled(false);

                                              setBounds(new
              Rectangle(100, 100, 700, 600));

                                              setBorder(new
              TitledBorder(UIManager.getBorder("TitledBorder.border"), "Enter
              Shifts", TitledBorder.LEADING, TitledBorder.TOP, null, new Color(0, 0,
              0)));

                                              setLayout(null);

                                             

                                             

                                             

                                              JLabel
              lblFacility = new JLabel("Facility");

                                              lblFacility.setBounds(42,
              84, 69, 14);

                                              add(lblFacility);

                                             

                                              JLabel
              label = new JLabel("7-3");

                                              label.setBounds(284,
              84, 46, 14);

                                              add(label);

                                             

                                              JLabel
              label_1 = new JLabel("3-11");

                                              label_1.setBounds(377,
              84, 46, 14);

                                              add(label_1);

                                             

                                              JLabel
              label_2 = new JLabel("11-3");

                                              label_2.setBounds(449,
              84, 46, 14);

                                              add(label_2);

                                             

                                              JComboBox
              comboBox = new JComboBox();

                              //            comboBox.setModel(new
              DefaultComboBoxModel(new String[] {"CNA", "LPN",
              "RN", "HHA", "CMA"}));

                                              comboBox.setModel(CandiPanel.candiTypecomboBox.getModel());

                                              comboBox.setBounds(176,
              128, 57, 20);

                                              add(comboBox);

                                             

                                              JComboBox
              comboBox_1 =  new JComboBox();

                                               comboBox_1.setModel(new
              DefaultComboBoxModel(new String[] {"0","1", "2",
              "3", "4", "5", "6", "7",
              "8", "9", "10"}));

                                              comboBox_1.setBounds(271,
              128, 46, 20);

                                              add(comboBox_1);

               

               

                                             

                                              JComboBox
              comboBox_2 =  new JComboBox();

                                               comboBox_2.setModel(new
              DefaultComboBoxModel(new String[] {"0","1", "2",
              "3", "4", "5", "6", "7",
              "8", "9"}));

                                              comboBox_2.setBounds(364,
              128, 46, 20);

                                              add(comboBox_2);

               

                                              JComboBox
              comboBox_3 = combcnt.getComboBox();

                                               comboBox_3.setModel(new
              DefaultComboBoxModel(new String[] {"0","1", "2",
              "3", "4", "5", "6", "7",
              "8", "9"}));

                                              comboBox_3.setBounds(434,
              128, 46, 20);

                                              add(comboBox_3);

                                             

               

                                             

                                             

                                              JLabel
              lblBook = new JLabel("Book");

                                              lblBook.setBounds(176,
              84, 69, 14);

                                              add(lblBook);

                                             

                                              comboBox_4.setModel(new
              DefaultComboBoxModel(new String[] {"select dept"}));

                                              comboBox_4.setBounds(30,
              128, 115, 20);

                                             

                                              add(comboBox_4);

                                             

                                   Object js = new Date();

                                              JSpinner
              spinner = new JSpinner();

                                              spinner.addChangeListener(new
              ChangeListener() {

                                                              public
              void stateChanged(ChangeEvent arg0) {

                                                                                 System.out.println( " State changed
              position Shift input --->"+spinner.getValue());     

                                                                                              ystr
              = dateFormat.format(spinner.getValue());                

                                                              }

                                              });

                                              spinner.addInputMethodListener(new
              InputMethodListener() {

                                                              public
              void caretPositionChanged(InputMethodEvent arg0) {

                                                                                 System.out.println( " Caret position Shift
              input --->"+ystr);                                      

                                                              }

                                                             

                                                              public
              void inputMethodTextChanged(InputMethodEvent arg0) {

                                                                                 System.out.println( " Input MethodShift
              input --->"+ystr);                                                       

                                                              }

                                              });

                                              spinner.addPropertyChangeListener(new
              PropertyChangeListener() {

                                                              public
              void propertyChange(PropertyChangeEvent arg0) {

                                                              System.out.println("Property
              changed --------------->>"+spinner.getValue());

                                                             

                                                               ChangeListener ch;

                                                              }

                                              });

                                              spinner.setModel(new
              SpinnerDateModel(new Date(), null, null, Calendar.DAY_OF_WEEK_IN_MONTH));

                                              spinner.setBounds(30,
              309, 115, 20);

                              

                                             

              //                if
              (spinner.getValue().getClass().getName())  );

                                              add(spinner);

                                             

                                               spinner.addChangeListener(new ChangeListener()
              {

               

                                                      @Override

                                                      public void stateChanged(ChangeEvent e)
              {

                                                          System.out.println("value
              changed: " + spinner.getValue());

                                                      }

                                                  });

               

                                             

                                             

              //// System.out.println(ystr+"
              <--ddddddddddddddddddd"+spinner.getValue());

                                              btnNewButton.addMouseListener(new
              MouseAdapter() {

                                                              @Override

                                                              public
              void mouseClicked(MouseEvent arg0) {

                                                                 String tstr =  comboBox_4.getSelectedItem().toString()+
              " , "+comboBox.getSelectedItem().toString()+ " , " +
              comboBox_1.getSelectedItem().toString()

                                                                                                 + " , " +
              comboBox_2.getSelectedItem().toString()+ " , " +
              comboBox_3.getSelectedItem().toString()

                                                                                                 + " , "+ystr  ;

                                                                

                                                 System.out.println( " Shift input
              --->"+tstr);

                       
              CalendarProgram1.insertShifts(tstr);

                       

                                                             

                                                                             

                                                              }

                                              });

                                              btnNewButton.setBounds(137,
              386, 89, 23);

                                              add(btnNewButton);

                                             

               

                                              comboBox_5.setBounds(30,
              174, 115, 20);

                                              add(comboBox_5);

                                             

                                              JComboBox
              comboBox_6 = new JComboBox();

                                              comboBox_6.setModel(new
              DefaultComboBoxModel(new String[] {"CNA", "LPN"}));

                                              comboBox_6.setBounds(176,
              174, 57, 20);

                                              add(comboBox_6);

                                             

                                              JComboBox
              comboBox_7 = new JComboBox();

                                              comboBox_7.setModel(new
              DefaultComboBoxModel(new String[] {"0", "1", "2",
              "3", "4", "5", "6", "7",
              "8", "9"}));

                                              comboBox_7.setBounds(271,
              174, 46, 20);

                                              add(comboBox_7);

                                             

                                              JComboBox
              comboBox_8 = new JComboBox();

                                              comboBox_8.setModel(new
              DefaultComboBoxModel(new String[] {"0", "1", "2",
              "3", "4", "5", "6", "7",
              "8", "9"}));

                                              comboBox_8.setBounds(364,
              174, 46, 20);

                                              add(comboBox_8);

                                             

                                              JComboBox
              comboBox_9 = new JComboBox();

                                              comboBox_9.setModel(new
              DefaultComboBoxModel(new String[] {"0", "1", "2",
              "3", "4", "5", "6", "7",
              "8", "9"}));

                                              comboBox_9.setBounds(434,
              174, 46, 20);

                                              add(comboBox_9);                        

                                             

                              }

              }

               

              class ComboCount{

                              JComboBox
              comboBox_1 = new JComboBox();

                              ComboCount(){

                              comboBox_1.setModel(new
              DefaultComboBoxModel(new String[] {"0","1", "2",
              "3", "4", "5", "6", "7",
              "8", "9", "10"}));

                              }

                              JComboBox
              getComboBox() {

                                              return
              comboBox_1;

                              }

               

              }

               

              package FinCal;

               

              import java.awt.Color;

              import java.awt.Rectangle;

               

              import javax.swing.JLabel;

              import javax.swing.JPanel;

              import javax.swing.JComboBox;

              import javax.swing.DefaultComboBoxModel;

              import javax.swing.JButton;

              import javax.swing.JTextField;

              import javax.swing.UIManager;

              import javax.swing.border.TitledBorder;

              import java.awt.event.MouseAdapter;

              import java.awt.event.MouseEvent;

              import javax.swing.JCheckBox;

               

              public class CandiPanel extends JPanel {

                               JTextField fname;

                                JTextField lname;

                              JButton
              btnNewButton_1 = new JButton("Save");          

                              private
              JTextField textField;

                              private
              JTextField textField_1;

                              private
              JTextField textField_2;

                              private
              JTextField txtMainSt;

                              private
              JTextField txtAp;

                              private
              JTextField txtCityname;

                              private
              JTextField textField_6;

                              private
              JTextField textField_7;

                              private
              JTextField textField_8;

                              private
              JTextField textField_9;

                              static
              JComboBox candiTypecomboBox = new JComboBox();

                              /**

                               * Create the panel.

                               */

                              public
              CandiPanel() {

                /*                         setLayout(null);

                                              System.out.println("Candi
              is called");

                                              JComboBox
              comboBox = new JComboBox();

                                              comboBox.setModel(new
              DefaultComboBoxModel(new String[] {"CNA", "LPN"}));

                                              comboBox.setBounds(148,
              333, 126, 20);

                                              add(comboBox);

                                             

                                              JButton
              btnNewButton = new JButton("New button");

                                              btnNewButton.setBounds(215,
              227, 89, 23);

                                              add(btnNewButton);

                                              setBorder(new
              TitledBorder(UIManager.getBorder("TitledBorder.border"), "Enter
              New Client Information", TitledBorder.LEADING, TitledBorder.TOP, null, new
              Color(0, 0, 0)));

                                              setLayout(null);

                                              */

                                             

                                              setEnabled(false);

                                              setBounds(new
              Rectangle(100, 100, 600, 700));

                                             setBorder(new
              TitledBorder(UIManager.getBorder("TitledBorder.border"), "Enter
              Candidate Information", TitledBorder.LEADING, TitledBorder.TOP, null, new
              Color(0, 0, 0)));

                                              setLayout(null);

                                             

                                             

                                              JButton
              btnNewButton = new JButton("New button");

                                              btnNewButton.setBounds(114,
              537, 89, 23);

                                              add(btnNewButton);

                                             

                                              JLabel
              lblFirstName = new JLabel("First Name");

                                              lblFirstName.setBounds(46,
              31, 69, 14);

                                              add(lblFirstName);

                                             

                                              JLabel
              lblLastName = new JLabel("Last Name");

                                              lblLastName.setBounds(46,
              78, 69, 14);

                                              add(lblLastName);

                                             

                                              fname
              = new JTextField();

                                              fname.setText("test1");

                                              fname.setBounds(125,
              28, 86, 20);

                                              add(fname);

                                              fname.setColumns(10);

                                             

                                              lname
              = new JTextField();

                                              lname.setText("lname2");

                                              lname.setBounds(124,
              75, 86, 20);

                                              add(lname);

                                              lname.setColumns(10);

                                             

               

                                             candiTypecomboBox.setModel(new
              DefaultComboBoxModel(new String[] {"FX", "RT",
              "DT", "F1", "INC"}));

                                              candiTypecomboBox.setBounds(315,
              28, 89, 20);

                                              add(candiTypecomboBox);

                                             

                                             

                                              btnNewButton_1.addMouseListener(new
              MouseAdapter() {

                                                              @Override

                                                              public
              void mouseClicked(MouseEvent arg0) {

                                                                             

                                                                              System.out.println("
              Candidate Information Submitted--->");

                                                                             

                                                                             

                                                              }

                                              });

                                              btnNewButton_1.setBounds(114,
              484, 89, 23);

                                              add(btnNewButton_1);

                                             

                                              JButton
              btnCancel = new JButton("Cancel");

                                              btnCancel.setBounds(374,
              484, 89, 23);

                                              add(btnCancel);

                                             

                                              textField
              = new JTextField();

                                              textField.setText("222-111-4444");

                                              textField.setColumns(10);

                                              textField.setBounds(125,
              106, 86, 20);

                                              add(textField);

                                             

                                              textField_1
              = new JTextField();

                                              textField_1.setText("3344444");

                                              textField_1.setColumns(10);

                                              textField_1.setBounds(354,
              138, 86, 20);

                                              add(textField_1);

                                             

                                              JLabel
              lblPhone = new JLabel("Cell");

                                              lblPhone.setBounds(46,
              103, 69, 14);

                                              add(lblPhone);

                                             

                                              JLabel
              lblPhone_1 = new JLabel("home Ph");

                                              lblPhone_1.setBounds(46,
              141, 69, 14);

                                              add(lblPhone_1);

                                             

                                              textField_2
              = new JTextField();

                                              textField_2.setText("488-122-9999");

                                              textField_2.setColumns(10);

                                              textField_2.setBounds(125,
              137, 86, 20);

                                              add(textField_2);

                                             

                                              txtMainSt
              = new JTextField();

                                              txtMainSt.setText("12
              main st.");

                                              txtMainSt.setColumns(10);

                                              txtMainSt.setBounds(125,
              192, 86, 20);

                                              add(txtMainSt);

                                             

                                              txtAp
              = new JTextField();

                                              txtAp.setText("ap2");

                                              txtAp.setColumns(10);

                                              txtAp.setBounds(125,
              223, 86, 20);

                                              add(txtAp);

                                             

                                              txtCityname
              = new JTextField();

                                              txtCityname.setText("city_name1");

                                              txtCityname.setColumns(10);

                                              txtCityname.setBounds(125,
              259, 86, 20);

                                              add(txtCityname);

                                             

                                              textField_6
              = new JTextField();

                                              textField_6.setText("07741");

                                              textField_6.setColumns(10);

                                              textField_6.setBounds(354,
              259, 86, 20);

                                              add(textField_6);

                                             

                                              JLabel
              lblStreetAdd = new JLabel("Street Add");

                                              lblStreetAdd.setBounds(46,
              195, 69, 14);

                                              add(lblStreetAdd);

                                             

                                              JLabel
              label = new JLabel("2.");

                                              label.setBounds(46,
              226, 69, 14);

                                              add(label);

                                             

                                              JLabel
              lblCityName = new JLabel("City Name");

                                              lblCityName.setBounds(46, 262,
              69, 14);

                                              add(lblCityName);

                                             

                                              textField_7
              = new JTextField();

                                              textField_7.setText("23");

                                              textField_7.setColumns(10);

                                              textField_7.setBounds(354,
              220, 86, 20);

                                              add(textField_7);

                                             

                                              JLabel
              lblWorkRadius = new JLabel("Work Radius");

                                              lblWorkRadius.setBounds(278,
              226, 69, 14);

                                              add(lblWorkRadius);

                                             

                                              JLabel
              lblLicNo = new JLabel("Lic No.");

                                              lblLicNo.setBounds(278,
              141, 69, 14);

                                              add(lblLicNo);

                                             

                                              JLabel
              lblLicExp = new JLabel("Lic Exp");

                                              lblLicExp.setBounds(278,
              177, 69, 14);

                                              add(lblLicExp);

                                             

                                              textField_8
              = new JTextField();

                                              textField_8.setText("2/3/33");

                                              textField_8.setColumns(10);

                                              textField_8.setBounds(354,
              169, 86, 20);

                                              add(textField_8);

                                             

                                              textField_9
              = new JTextField();

                                              textField_9.setText("20.23");

                                              textField_9.setColumns(10);

                                              textField_9.setBounds(354,
              75, 86, 20);

                                              add(textField_9);

                                             

                                              JLabel
              lblRate = new JLabel("Rate");

                                              lblRate.setBounds(278,
              78, 69, 14);

                                              add(lblRate);

                                             

                                              JComboBox
              comboBox_2 = new JComboBox();

                                              comboBox_2.setModel(new
              DefaultComboBoxModel(new String[] {"NJ", "NY",
              "PA"}));

                                              comboBox_2.setBounds(237,
              259, 56, 20);

                                              add(comboBox_2);

                                             

                                              JLabel
              lblZip = new JLabel("zip");

                                              lblZip.setBounds(313,
              262, 28, 14);

                                              add(lblZip);

                                             

                                              JLabel
              lblDesiredShift = new JLabel("Desired Shift");

                                              lblDesiredShift.setBounds(25,
              351, 69, 14);

                                              add(lblDesiredShift);

                                             

                                              JCheckBox
              checkBox = new JCheckBox("7-3");

                                              checkBox.setSelected(true);

                                              checkBox.setBounds(114,
              347, 97, 23);

                                              add(checkBox);

                                             

                                              JCheckBox
              checkBox_1 = new JCheckBox("3-11");

                                              checkBox_1.setSelected(true);

                                              checkBox_1.setBounds(208,
              347, 69, 23);

                                              add(checkBox_1);

                                             

                                              JCheckBox
              checkBox_2 = new JCheckBox("11-7");

                                              checkBox_2.setSelected(true);

                                              checkBox_2.setBounds(318,
              347, 86, 23);

                                              add(checkBox_2);

                                             

                                              JCheckBox
              chckbxSunday = new JCheckBox("Sunday");

                                              chckbxSunday.setSelected(true);

                                              chckbxSunday.setBounds(114,
              375, 69, 23);

                                              add(chckbxSunday);

                                             

                                              JCheckBox
              chckbxMonday = new JCheckBox("Mon");

                                              chckbxMonday.setSelected(true);

                                              chckbxMonday.setBounds(208,
              373, 69, 23);

                                              add(chckbxMonday);

                                             

                                              JCheckBox
              chckbxTue = new JCheckBox("Tue");

                                              chckbxTue.setSelected(true);

                                              chckbxTue.setBounds(294,
              373, 69, 23);

                                              add(chckbxTue);

                                             

                                              JCheckBox
              chckbxWed = new JCheckBox("Wed");

                                              chckbxWed.setSelected(true);

                                              chckbxWed.setBounds(374,
              373, 69, 23);

                                              add(chckbxWed);

                                             

                                              JCheckBox
              chckbxThu = new JCheckBox("Thu");

                                              chckbxThu.setSelected(true);

                                              chckbxThu.setBounds(114,
              403, 69, 23);

                                              add(chckbxThu);

                                             

                                              JCheckBox
              chckbxFri = new JCheckBox("Fri");

                                              chckbxFri.setSelected(true);

                                              chckbxFri.setBounds(208,
              399, 69, 23);

                                              add(chckbxFri);

                                             

                                              JCheckBox
              chckbxSat = new JCheckBox("Sat");

                                              chckbxSat.setSelected(true);

                                              chckbxSat.setBounds(294,
              403, 69, 23);

                                              add(chckbxSat);

                                             

                                              JLabel
              lblDays = new JLabel("Days");

                                              lblDays.setBounds(25,
              379, 69, 14);

                                              add(lblDays);

                              }

              }

               

               

               

               

               

              package FinCal;

               

              import javax.swing.JPanel;

              import javax.swing.border.TitledBorder;

              import java.awt.Rectangle;

              import javax.swing.JTextField;

              import javax.swing.JButton;

              import javax.swing.JLabel;

              import javax.swing.UIManager;

              import java.awt.Color;

              import javax.swing.JList;

              import javax.swing.JComboBox;

              import javax.swing.DefaultComboBoxModel;

              import java.awt.event.MouseAdapter;

              import java.awt.event.MouseEvent;

               

              public class ClientPanel extends JPanel {

                              private
              JTextField textField;

                              private
              JTextField textField_1;

               

                              /**

                               * Create the panel.

                               */

                              public
              ClientPanel() {

                                              setEnabled(false);

                                              setBounds(new
              Rectangle(100, 100, 400, 600));

                                              setBorder(new
              TitledBorder(UIManager.getBorder("TitledBorder.border"), "Enter
              New Client Information", TitledBorder.LEADING, TitledBorder.TOP, null, new
              Color(0, 0, 0)));

                                              setLayout(null);

                                             

                                              textField
              = new JTextField();

                                              textField.setBounds(154,
              166, 113, 20);

                                              add(textField);

                                              textField.setColumns(10);

                                             

                                              JButton
              btnNewButton = new JButton("save");

               

                                              btnNewButton.setBounds(120,
              391, 89, 23);

                                              add(btnNewButton);

                                             

                                              JLabel
              lblFirstName = new JLabel("Name of Fac");

                                              lblFirstName.setBounds(58,
              169, 69, 14);

                                              add(lblFirstName);

                                             

                                              JLabel
              lblLastName = new JLabel("Contact Person");

                                              lblLastName.setBounds(38,
              216, 89, 14);

                                              add(lblLastName);

                                             

                                              textField_1
              = new JTextField();

                                              textField_1.setColumns(10);

                                              textField_1.setBounds(154,
              213, 113, 20);

                                              add(textField_1);

                                             

                                              btnNewButton.addMouseListener(new
              MouseAdapter() {

                                                              @Override

                                                              public
              void mouseClicked(MouseEvent arg0) {

                                                                             

                                                              String
              tstr =         textField.getText() +
              " ,  " +textField_1.getText();

                                                                              CalendarProgram1.insertCust(tstr);

                                                                             

                                                              }

                                              });

                                             

                                             

               

                              }

              }

               

              package FinCal;

               

              import javax.swing.JPanel;

              import javax.swing.border.EtchedBorder;

              import java.awt.Color;

              import javax.swing.JButton;

              import java.awt.Rectangle;

              import java.awt.event.MouseAdapter;

              import java.awt.event.MouseEvent;

               

              public class MainControl extends JPanel {

                              JButton
              btnNewButton = new JButton("Calendar");

                              JButton
              btnNewClient = new JButton("New Client");      

                              JButton
              btnNewCandidate = new JButton("New Candidate");

                              JButton
              btnNewButton_1 = new JButton("Shifts");

                
              JButton btnAssigments = new JButton("Assigments");

                              /*
              Create the panel.

                               */

                              public
              MainControl() {

               

                                              addMouseListener(new
              MouseAdapter() {

                                                              @Override

                                                              public
              void mouseClicked(MouseEvent arg0) {

                                                                              System.out.println("
              Enter Client");

                                                              }

                                              });

                                              setBounds(new
              Rectangle(0, 0, 800, 80));

                                              setBorder(new
              EtchedBorder(EtchedBorder.RAISED, Color.CYAN, Color.BLACK));

                                             

               

                                              btnNewClient.setBounds(376,
              7, 89, 23);

                                              btnNewClient.addMouseListener(new
              MouseAdapter() {

                                                              @Override

                                                              public
              void mouseClicked(MouseEvent arg0) {

                                                                              System.out.println("
              in Main Control Enter Client button pressed");

                                                              }

                                              });

                                              setLayout(null);

                                             

               

                                              btnNewButton.addMouseListener(new
              MouseAdapter() {

                                                              @Override

                                                              public
              void mouseClicked(MouseEvent arg0) {

                                                                              System.out.println("In
              Main Control Calendar button pressed");

                                                              }

                                              });

                                              btnNewButton.setBounds(376,
              43, 89, 23);

                                              add(btnNewButton);

                                              add(btnNewClient);

                                             

               

                                              btnNewCandidate.addMouseListener(new
              MouseAdapter() {

                                                              @Override

                                                              public
              void mouseClicked(MouseEvent arg0) {

                                                              }

                                              });

                                              btnNewCandidate.setBounds(253,
              7, 105, 23);

                                              add(btnNewCandidate);

                                              btnNewButton_1.addMouseListener(new
              MouseAdapter() {

                                                              @Override

                                                              public
              void mouseClicked(MouseEvent arg0) {

                                                                              System.out.println("
              Shifts in Main");

                                                              }

                                              });

                                              btnNewButton_1.setBounds(253,
              43, 112, 23);

                                             

                                              add(btnNewButton_1);

                                              btnAssigments.addMouseListener(new
              MouseAdapter() {

                                                              @Override

                                                              public
              void mouseClicked(MouseEvent arg0) {

                                                              }

                                              });

                                              btnAssigments.setBounds(475,
              7, 89, 23);

                                             

                                              add(btnAssigments);

               

                              }

               

              }

               

              package
              FinCal;

               

              1. import
                javax.swing.border.*;
              2. import
                javax.swing.event.*;
              3. import
                javax.swing.table.*;

               

              1. import
                java.awt.event.*;

               

              1. import
                javax.swing.*;

               

              1. import
                java.util.*;
              2. import
                java.util.List;
              3. import
                java.awt.*;

                

              public class
              JTextAreaTableExample extends JFrame {

               

                public JTextAreaTableExample() {

                  super( "JTextAreaTableExample
              Example" );

                

                  DefaultTableModel dtm = new
              DefaultTableModel() {

                     // make first cell uneditable

                     public boolean isCellEditable(int row,
              int column)

                     {

                        return !(column == 0);

                     }

                    

                  };

               

                  dtm.setDataVector(new Object[][]{{
              "JTextArea1", "This is a testnon long linesn" ,"col2
              value"},

                                                   {
              "JTextArea2",  "Hello
              world"  ,"col3 valu"}},

                                    new Object[]{
              "String","JTextArea","COL2"});

                                   

                  JTable table = new JTable(dtm);

                
              table.getColumn("JTextArea").setCellRenderer(new
              TextAreaRenderer("DA"));

                  //
              table.getColumn("JTextArea").setCellEditor(new
              TextAreaEditor("FF"));

                   

                  

                
              table.getColumn("COL2").setCellRenderer(new
              TextAreaRenderer("SD"));

                 //
              table.getColumn("COL2").setCellEditor(new
              TextAreaEditor("FF"));

                 

               

                  table.setRowHeight(80);

                  JScrollPane scroll = new
              JScrollPane(table);

                  getContentPane().add(scroll);

               

                  setSize( 800, 700 );

                  setVisible(true);

                }

               

                public static void main(String[] args) {

                  JTextAreaTableExample frame = new
              JTextAreaTableExample();

                  frame.addWindowListener(new WindowAdapter()
              {

                    public void windowClosing(WindowEvent e)
              {

                      System.exit(0);

                    }

                  });

                }

              }

                

              class TextAreaRenderer
              extends JScrollPane implements TableCellRenderer

              {

                 JTextArea textarea;

                 JLabel jlabel ;

                 CalPanel cp1 = new CalPanel();

                 TextAreaRenderer(){

                                

                 }

                 public TextAreaRenderer(String t) {

                                

                    textarea = new JTextArea();

                    textarea.setLineWrap(true);

                    textarea.setWrapStyleWord(true);

                    jlabel = new JLabel("fdsf");

                   

               

                    textarea.setBorder(new TitledBorder(t));

                    textarea.add(jlabel);

                    System.out.println("JJJJJJJJ");

                   // getViewport().add(textarea);

                   // jlabel.setBounds(10, 20, 46, 14);

                   // cp.add(jlabel,10,20,46,14);

                 

                   // getViewport().add(jlabel);

                   

                   

                     }

               

                 public Component
              getTableCellRendererComponent(JTable table, Object value,

                                                boolean isSelected, boolean hasFocus,

                                                int row, int
              column)

                 {

                              // System.out.println("6
              Exiting value --->"+value);

                              
              //System.exit(9);

                              //   CalPanel cp1 = new CalPanel();

                               // cp1.setdate("DS"); 

                              //
              cp1.setdate("sddd");

                    //    
              cp1.setdate1("dddd");

                               String datevalue = value+"";

                               String monthvalue =
              (CalendarProgram1.currentMonth+1)+"";

                              

                               try {

                                              int dateD =
              Integer.valueOf(value+"");

                                              if (dateD <
              10) {

                                                              datevalue
              = "0"+datevalue ;

                                              }                             

                               }catch(Exception kkk) {}

                              

                               try {

                                                              int
              dateM = Integer.valueOf(monthvalue+"");

                                                              if
              (dateM < 10) {

                                                                              monthvalue
              = "0"+monthvalue ;

                                                              }                             

                                               }catch(Exception kkk) {}

                                             

                              

                              
              String mydate =
              CalendarProgram1.currentYear+"-"+monthvalue+"-"+datevalue;

                              
              CalendarProgram1.viewingDay = mydate;

                               String vs = null;

                              /////  System.out.println(mydate+"Shift
              information  searching
              for------------------->"+CalendarProgram1.getDataByDate(mydate));

                             

                               List mydlist =
              CalendarProgram1.getDataByDate(mydate);

                              

                   cp1.label.setText(" ");              

                   cp1.label_1.setText(" ");

                   cp1.label_2.setText(" ");

                   cp1.label_3.setText(" ");

                   cp1.label_4.setText(" ");

                   cp1.label_5.setText(" ");

                  

                               cp1.lblNewLabel.setText(" ");

                  

                   if ((value != null) ) {

                                              

                              
              if (mydlist  !=null) {        

              try {                                       


              cp1.lblNewLabel.setText(mydlist.get(0)+"("+mydlist.get(1)+")"+mydlist.get(2)+":"+mydlist.get(3)+":"+mydlist.get(4)+"");
              }catch(Exception jj) {}

                     //cp1.label.setText(mydlist.get(12)+"("+mydlist.get(13)+")"+mydlist.get(2)+":"+mydlist.get(3)+"");               

                     try {                                

                                 cp1.label_1.setText(mydlist.get(11)+"("+mydlist.get(12)+")"+mydlist.get(13)+":"+mydlist.get(14)+":"+mydlist.get(15)+"");
              }catch(Exception jj) {}

                  try { cp1.label_2.setText(mydlist.get(22)+"("+mydlist.get(23)+")"+mydlist.get(24)+":"+mydlist.get(25)+":"+mydlist.get(26)+"");   }catch(Exception jj) {}

                  try {
              cp1.label_3.setText(mydlist.get(33)+"("+mydlist.get(34)+")"+mydlist.get(35)+":"+mydlist.get(36)+":"+mydlist.get(37)+"");   }catch(Exception jj) {}

                  try {
              cp1.label_4.setText(mydlist.get(44)+"("+mydlist.get(45)+")"+mydlist.get(46)+":"+mydlist.get(47)+":"+mydlist.get(48)+"");   }catch(Exception jj) {}

                  try {
              cp1.label_5.setText(mydlist.get(55)+"("+mydlist.get(56)+")"+mydlist.get(57)+":"+mydlist.get(58)+":"+mydlist.get(59)+"");   }catch(Exception jj) {}

                  try {
              cp1.label.setText(mydlist.get(66)+"("+mydlist.get(67)+")"+mydlist.get(68)+":"+mydlist.get(69)+":"+mydlist.get(70)+"");   }catch(Exception jj) {}

               

                 

                 

                 

                  //    
              cp1.label_2.setText(mydlist.get(3)+"");

              //   
              cp1.label_3.setText(mydlist.get(4)+"");

              //cp1.label_4.setText(mydlist.get(5)+"");                            

               

               

                                                for ( int j=0;j<mydlist.size();j++) {

                                                                              System.out.print("
              "+ mydlist.get(j));

                                                             

                                                                              if
              ( (j != 0) && ((j+1) % CalendarProgram1.daySize == 0)) {

                                                                                  

                                              /////                           System.out.println(   "
              In Painter " +mydate);

                                                                              }

                                                                }

                              
              }

                                                                                              

                                               cp1.lblHarin.setText("My Test");

                                              

                                

                                              

                                              //
              cp1.lblNewLabel.setText(CalendarProgram1.allContent[0][0][0]);

               

                                  // cp1.lblHarin.setText("
              "+value);

                             

                                  

                                  

                                  

                                  

                                  

                                   cp1.setdate(" "+value);

                                  

                                      getViewport().add(cp1);    

               

                               }else {

                                               cp1.setBackground(Color.LIGHT_GRAY);

                                               getViewport().remove(cp1);

                                              

                               }

                                

                /* Component cell =
              getTableCellRendererComponent(

                                                                 table, value, isSelected, hasFocus, row,
              column);

                              */  

                               // 
              setBackground(table.getBackground());

                               /* 

                                 if (isSelected) {

                       setForeground(table.getSelectionForeground());

                     
              setBackground(table.getSelectionBackground());

                     
              textarea.setForeground(table.getSelectionForeground());

                     
              textarea.setBackground(table.getSelectionBackground());

                      // textarea.setBackground(Color.blue);

                    } else {

                       setForeground(table.getForeground());

                       setBackground(table.getBackground());

                     
              textarea.setForeground(table.getForeground());

                     
              textarea.setBackground(table.getBackground());

                    }

               

                    try{textarea.setText((String) value);

                                }catch(Exception ex) {

                               

                                };

                              //  textarea.add(cell);     

                   

                    textarea.setCaretPosition(0);

                   

                    */

                               revalidate();

                    return this;

                 }

              }

               

              class
              TextAreaEditor implements TableCellEditor {

                 protected JScrollPane scrollpane;

                 protected JTextArea textarea;

                 CalPanel cs = new CalPanel();

                 public TextAreaEditor() {

                              
              // super(new JCheckBox());

                 }

               

                 public TextAreaEditor(String tt ) {

                              
              // super(new JCheckBox());

                   // this.cancelCellEditing();

                                

                    scrollpane = new JScrollPane();

                    textarea = new JTextArea(); 

                    textarea.setLineWrap(true);

                    textarea.setWrapStyleWord(true);

                    JButton jb = new JButton("KKK");

                    jb.setVisible(true);

               

                    JPanel panel = new JPanel();

                    panel.setBackground(Color.BLACK);

                    panel.add( new
              JButton("SDFDFDSF"));

                    panel.setVisible(true);

                   

                   

                    //textarea.add(jb);

              //   
              textarea.revalidate();

                          ////     textarea.add(cs);

                   

                    textarea.setBorder(new TitledBorder(tt));

                  //
              scrollpane.getViewport().add(textarea);

                  //
              scrollpane.revalidate();

                //  
              textarea.revalidate();

                 }

               

                 public Component getTableCellEditorComponent(JTable
              table, Object value,

                                                 boolean
              isSelected, int row, int column) {

                   // textarea.setText((String) value);

               

                               // 
              String mvalue = Integer.toString(value);

                              
              try { textarea.setText( (String) value); } catch(Exception e) {
              System.out.println(e);}

                              
              System.out.println("ssssssssssssssssssss");

                                 

                    return scrollpane;

                 }

               

                 public Object getCellEditorValue() {

                    return textarea.getText();

                 }

              @Override

              public void
              addCellEditorListener(CellEditorListener arg0) {

                              // TODO Auto-generated method
              stub

                             

              }

              @Override

              public void
              cancelCellEditing() {

                              // TODO Auto-generated method
              stub

                             

              }

              @Override

              public boolean
              isCellEditable(EventObject arg0) {

                              // TODO Auto-generated method
              stub

                              return false;

              }

              @Override

              public void
              removeCellEditorListener(CellEditorListener arg0) {

                              // TODO Auto-generated method
              stub

                             

              }

              @Override

              public boolean
              shouldSelectCell(EventObject arg0) {

                              // TODO Auto-generated method
              stub

                              return false;

              }

              @Override

              public boolean
              stopCellEditing() {

                              // TODO Auto-generated method
              stub

                              return false;

              }

              }

               

               

              /*

              class CalPanel
              extends JPanel {

               

               

                             

                              JLabel
              lblHarin = new JLabel("Main Class Hardsafdsf "

                                                              +
              "dfaddsfdsaf in");

              JLabel lblNewLabel = new JLabel("New
              label");

                             

                              public CalPanel() {

                                              setLayout(null);

                                             

                                              lblHarin.setBounds(10,
              11, 146, 14);

                                              add(lblHarin);

                             

                                              lblNewLabel.setBounds(10,
              24, 112, 14);

                                              add(lblNewLabel);

                                             

                                              JFormattedTextField
              formattedTextField = new JFormattedTextField();

                                              formattedTextField.setBounds(10,
              43, 112, 20);

                                              add(formattedTextField);

               

                              }

                              public void setdate(String str)
              {

                                              lblHarin.setText(str);

                              }

                              public void setdate1(String str)
              {

                                              lblNewLabel.setText(str);

                              }

                             

              }

               

              */

              • 4. Re: Code throwing Null exceptoin
                hphanjra-JavaNet

                if you want to compile and run the entire my test program ... this is for testing only.  It has no data etc. 

                • 5. Re: Code throwing Null exceptoin
                  hphanjra-JavaNet

                  package FinCal; import javax.swing.border.*; import javax.swing.event.*; import javax.swing.table.*; import java.awt.event.*; import javax.swing.*; import java.util.*; import java.util.List; import java.awt.*;   public class JTextAreaTableExample extends JFrame {     public JTextAreaTableExample() {     super( "JTextAreaTableExample Example" );       DefaultTableModel dtm = new DefaultTableModel() {       // make first cell uneditable       public boolean isCellEditable(int row, int column)       {           return !(column == 0);       }           };       dtm.setDataVector(new Object[][]{{ "JTextArea1", "This is a testnon long linesn" ,"col2 value"},                                     { "JTextArea2",  "Hello world"  ,"col3 valu"}},                       new Object[]{ "String","JTextArea","COL2"});                           JTable table = new JTable(dtm);     table.getColumn("JTextArea").setCellRenderer(new TextAreaRenderer("DA"));     // table.getColumn("JTextArea").setCellEditor(new TextAreaEditor("FF"));               table.getColumn("COL2").setCellRenderer(new TextAreaRenderer("SD"));   // table.getColumn("COL2").setCellEditor(new TextAreaEditor("FF"));           table.setRowHeight(80);     JScrollPane scroll = new JScrollPane(table);     getContentPane().add(scroll);       setSize( 800, 700 );     setVisible(true);   }     public static void main(String[] args) {     JTextAreaTableExample frame = new JTextAreaTableExample();     frame.addWindowListener(new WindowAdapter() {       public void windowClosing(WindowEvent e) {         System.exit(0);       }     });   } }   class TextAreaRenderer extends JScrollPane implements TableCellRenderer {   JTextArea textarea;   JLabel jlabel ;   CalPanel cp1 = new CalPanel();   TextAreaRenderer(){     }   public TextAreaRenderer(String t) {         textarea = new JTextArea();       textarea.setLineWrap(true);       textarea.setWrapStyleWord(true);       jlabel = new JLabel("fdsf");             textarea.setBorder(new TitledBorder(t));       textarea.add(jlabel);       System.out.println("JJJJJJJJ");     // getViewport().add(textarea);     // jlabel.setBounds(10, 20, 46, 14);     // cp.add(jlabel,10,20,46,14);         // getViewport().add(jlabel);                   }     public Component getTableCellRendererComponent(JTable table, Object value,                                   boolean isSelected, boolean hasFocus,                                   int row, int column)   { // System.out.println("6 Exiting value --->"+value);   //System.exit(9); //  CalPanel cp1 = new CalPanel(); // cp1.setdate("DS");  // cp1.setdate("sddd");       //      cp1.setdate1("dddd"); String datevalue = value+""; String monthvalue = (CalendarProgram1.currentMonth+1)+""; try { int dateD = Integer.valueOf(value+""); if (dateD < 10) { datevalue = "0"+datevalue ; } }catch(Exception kkk) {} try { int dateM = Integer.valueOf(monthvalue+""); if (dateM < 10) { monthvalue = "0"+monthvalue ; } }catch(Exception kkk) {}   String mydate = CalendarProgram1.currentYear+"-"+monthvalue+"-"+datevalue;   CalendarProgram1.viewingDay = mydate; String vs = null; /////  System.out.println(mydate+"Shift information  searching for------------------->"+CalendarProgram1.getDataByDate(mydate)); List mydlist = CalendarProgram1.getDataByDate(mydate);     cp1.label.setText(" ");     cp1.label_1.setText(" ");     cp1.label_2.setText(" ");     cp1.label_3.setText(" ");     cp1.label_4.setText(" ");     cp1.label_5.setText(" ");     cp1.lblNewLabel.setText(" ");         if ((value != null) ) {   if (mydlist  !=null) { if ( !CalendarProgram1.CandiView ){   try { cp1.lblNewLabel.setText(mydlist.get(0)+"("+mydlist.get(1)+")"+mydlist.get(2)+":"+mydlist.get(3)+":"+mydlist.get(4)+""); }catch(Exception jj) {}       //cp1.label.setText(mydlist.get(12)+"("+mydlist.get(13)+")"+mydlist.get(2)+":"+mydlist.get(3)+"");       try {       cp1.label_1.setText(mydlist.get(11)+"("+mydlist.get(12)+")"+mydlist.get(13)+":"+mydlist.get(14)+":"+mydlist.get(15)+""); }catch(Exception jj) {}     try { cp1.label_2.setText(mydlist.get(22)+"("+mydlist.get(23)+")"+mydlist.get(24)+":"+mydlist.get(25)+":"+mydlist.get(26)+"");  }catch(Exception jj) {}     try { cp1.label_3.setText(mydlist.get(33)+"("+mydlist.get(34)+")"+mydlist.get(35)+":"+mydlist.get(36)+":"+mydlist.get(37)+"");  }catch(Exception jj) {}     try { cp1.label_4.setText(mydlist.get(44)+"("+mydlist.get(45)+")"+mydlist.get(46)+":"+mydlist.get(47)+":"+mydlist.get(48)+"");  }catch(Exception jj) {}     try { cp1.label_5.setText(mydlist.get(55)+"("+mydlist.get(56)+")"+mydlist.get(57)+":"+mydlist.get(58)+":"+mydlist.get(59)+"");  }catch(Exception jj) {}     try { cp1.label.setText(mydlist.get(66)+"("+mydlist.get(67)+")"+mydlist.get(68)+":"+mydlist.get(69)+":"+mydlist.get(70)+"");  }catch(Exception jj) {}     }         //      cp1.label_2.setText(mydlist.get(3)+""); //    cp1.label_3.setText(mydlist.get(4)+""); //cp1.label_4.setText(mydlist.get(5)+"");   for ( int j=0;j<mydlist.size();j++) { System.out.print(" "+ mydlist.get(j)); if ( (j != 0) && ((j+1) % CalendarProgram1.daySize == 0)) {     /////     System.out.println(  "  In Painter " +mydate); }   }   } cp1.lblHarin.setText("My Test");   // cp1.lblNewLabel.setText(CalendarProgram1.allContent[0][0][0]);     // cp1.lblHarin.setText(" "+value);                         cp1.setdate(" "+value);             getViewport().add(cp1);    }else { cp1.setBackground(Color.LIGHT_GRAY); getViewport().remove(cp1); }     /* Component cell = getTableCellRendererComponent(               table, value, isSelected, hasFocus, row, column); */  //  setBackground(table.getBackground()); /*    if (isSelected) {         setForeground(table.getSelectionForeground());         setBackground(table.getSelectionBackground());         textarea.setForeground(table.getSelectionForeground());         textarea.setBackground(table.getSelectionBackground());         // textarea.setBackground(Color.blue);       } else {         setForeground(table.getForeground());         setBackground(table.getBackground());         textarea.setForeground(table.getForeground());         textarea.setBackground(table.getBackground());       }         try{textarea.setText((String) value);       }catch(Exception ex) {             };     //  textarea.add(cell);               textarea.setCaretPosition(0);             */ revalidate();       return this;   } }   class TextAreaEditor implements TableCellEditor {   protected JScrollPane scrollpane;   protected JTextArea textarea;   CalPanel cs = new CalPanel();   public TextAreaEditor() {   // super(new JCheckBox());   }   public TextAreaEditor(String tt ) {   // super(new JCheckBox());     // this.cancelCellEditing();         scrollpane = new JScrollPane();       textarea = new JTextArea();        textarea.setLineWrap(true);       textarea.setWrapStyleWord(true);       JButton jb = new JButton("KKK");       jb.setVisible(true);       JPanel panel = new JPanel();       panel.setBackground(Color.BLACK);       panel.add( new JButton("SDFDFDSF"));       panel.setVisible(true);                   //textarea.add(jb); //    textarea.revalidate();             ////    textarea.add(cs);             textarea.setBorder(new TitledBorder(tt));     //  scrollpane.getViewport().add(textarea);     //  scrollpane.revalidate();   //    textarea.revalidate();   }     public Component getTableCellEditorComponent(JTable table, Object value,                                   boolean isSelected, int row, int column) {     // textarea.setText((String) value); //  String mvalue = Integer.toString(value);   try { textarea.setText( (String) value); } catch(Exception e) { System.out.println(e);}   System.out.println("ssssssssssssssssssss");           return scrollpane;   }     public Object getCellEditorValue() {       return textarea.getText();   } @Override public void addCellEditorListener(CellEditorListener arg0) { // TODO Auto-generated method stub } @Override public void cancelCellEditing() { // TODO Auto-generated method stub } @Override public boolean isCellEditable(EventObject arg0) { // TODO Auto-generated method stub return false; } @Override public void removeCellEditorListener(CellEditorListener arg0) { // TODO Auto-generated method stub } @Override public boolean shouldSelectCell(EventObject arg0) { // TODO Auto-generated method stub return false; } @Override public boolean stopCellEditing() { // TODO Auto-generated method stub return false; } } /* class CalPanel extends JPanel { JLabel lblHarin = new JLabel("Main Class Hardsafdsf " + "dfaddsfdsaf in"); JLabel lblNewLabel = new JLabel("New label"); public CalPanel() { setLayout(null); lblHarin.setBounds(10, 11, 146, 14); add(lblHarin); lblNewLabel.setBounds(10, 24, 112, 14); add(lblNewLabel); JFormattedTextField formattedTextField = new JFormattedTextField(); formattedTextField.setBounds(10, 43, 112, 20); add(formattedTextField); } public void setdate(String str) { lblHarin.setText(str); } public void setdate1(String str) { lblNewLabel.setText(str); } } */ package FinCal; import javax.swing.JPanel; import javax.swing.border.EtchedBorder; import java.awt.Color; import javax.swing.JButton; import java.awt.Rectangle; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.awt.event.ActionListener; import java.awt.event.ActionEvent; import javax.swing.JComboBox; import javax.swing.JRadioButton; public class MainControl extends JPanel { JButton btnNewButton = new JButton("Calendar"); JButton btnNewClient = new JButton("New Client"); JButton btnNewCandidate = new JButton("New Candidate"); JButton btnNewButton_1 = new JButton("Shifts");     JButton btnAssigments = new JButton("Assigments"); JButton btnNewButton_2 = new JButton("Print");     /* Create the panel. */ public MainControl() { addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent arg0) { System.out.println(" Enter Client"); } }); setBounds(new Rectangle(0, 0, 800, 80)); setBorder(new EtchedBorder(EtchedBorder.RAISED, Color.CYAN, Color.BLACK)); btnNewClient.setBounds(376, 7, 89, 23); btnNewClient.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent arg0) { System.out.println(" in Main Control Enter Client button pressed"); } }); setLayout(null); btnNewButton.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent arg0) { System.out.println("In Main Control Calendar button pressed"); } }); btnNewButton.setBounds(376, 43, 89, 23); add(btnNewButton); add(btnNewClient); btnNewCandidate.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent arg0) { } }); btnNewCandidate.setBounds(253, 7, 105, 23); add(btnNewCandidate); btnNewButton_1.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent arg0) { System.out.println(" Shifts in Main"); } }); btnNewButton_1.setBounds(253, 43, 112, 23); add(btnNewButton_1); btnAssigments.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent arg0) { } }); btnAssigments.setBounds(475, 7, 89, 23); add(btnAssigments); btnNewButton_2.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { } }); btnNewButton_2.setBounds(10, 22, 89, 23); add(btnNewButton_2); JComboBox comboBox = new JComboBox(); comboBox.setBounds(506, 44, 105, 20); add(comboBox); JRadioButton rdbtnCandiview = new JRadioButton("CandiView"); rdbtnCandiview.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { if ( rdbtnCandiview.isSelected()) { CalendarProgram1.CandiView = true; }else CalendarProgram1.CandiView = false; } }); rdbtnCandiview.setBounds(627, 7, 109, 23); add(rdbtnCandiview); } } package FinCal; import javax.swing.JPanel; import javax.swing.border.EtchedBorder; import java.awt.Color; import javax.swing.JButton; import java.awt.Rectangle; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.awt.event.ActionListener; import java.awt.event.ActionEvent; import javax.swing.JComboBox; import javax.swing.JRadioButton; public class MainControl extends JPanel { JButton btnNewButton = new JButton("Calendar"); JButton btnNewClient = new JButton("New Client"); JButton btnNewCandidate = new JButton("New Candidate"); JButton btnNewButton_1 = new JButton("Shifts");     JButton btnAssigments = new JButton("Assigments"); JButton btnNewButton_2 = new JButton("Print");     /* Create the panel. */ public MainControl() { addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent arg0) { System.out.println(" Enter Client"); } }); setBounds(new Rectangle(0, 0, 800, 80)); setBorder(new EtchedBorder(EtchedBorder.RAISED, Color.CYAN, Color.BLACK)); btnNewClient.setBounds(376, 7, 89, 23); btnNewClient.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent arg0) { System.out.println(" in Main Control Enter Client button pressed"); } }); setLayout(null); btnNewButton.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent arg0) { System.out.println("In Main Control Calendar button pressed"); } }); btnNewButton.setBounds(376, 43, 89, 23); add(btnNewButton); add(btnNewClient); btnNewCandidate.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent arg0) { } }); btnNewCandidate.setBounds(253, 7, 105, 23); add(btnNewCandidate); btnNewButton_1.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent arg0) { System.out.println(" Shifts in Main"); } }); btnNewButton_1.setBounds(253, 43, 112, 23); add(btnNewButton_1); btnAssigments.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent arg0) { } }); btnAssigments.setBounds(475, 7, 89, 23); add(btnAssigments); btnNewButton_2.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { } }); btnNewButton_2.setBounds(10, 22, 89, 23); add(btnNewButton_2); JComboBox comboBox = new JComboBox(); comboBox.setBounds(506, 44, 105, 20); add(comboBox); JRadioButton rdbtnCandiview = new JRadioButton("CandiView"); rdbtnCandiview.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { if ( rdbtnCandiview.isSelected()) { CalendarProgram1.CandiView = true; }else CalendarProgram1.CandiView = false; } }); rdbtnCandiview.setBounds(627, 7, 109, 23); add(rdbtnCandiview); } } package FinCal; /* * mc.btnNewButton_2.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) {     PrinterJob pjob = PrinterJob.getPrinterJob();     PageFormat preformat = pjob.defaultPage();     preformat.setOrientation(PageFormat.LANDSCAPE);     PageFormat postformat = pjob.pageDialog(preformat);     //If user does not hit cancel then print.     if (preformat != postformat) {         //Set print component         pjob.setPrintable(new Printer((Component)frmMain), postformat);         if (pjob.printDialog()) {           try {  pjob.print(); }catch(Exception E) {}         }     }         } }); */ import java.awt.Component; import java.awt.Dimension; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.print.PageFormat; import java.awt.print.Printable; import java.awt.print.PrinterException; import java.awt.print.PrinterJob; public  class Printer implements Printable {     final Component comp;     public Printer(Component comp){         this.comp = comp;     }     @Override     public int print(Graphics g, PageFormat format, int page_index)             throws PrinterException {         if (page_index > 0) {             return Printable.NO_SUCH_PAGE;         }         // get the bounds of the component         Dimension dim = comp.getSize();         double cHeight = dim.getHeight();         double cWidth = dim.getWidth();         // get the bounds of the printable area         double pHeight = format.getImageableHeight();         double pWidth = format.getImageableWidth();         double pXStart = format.getImageableX();         double pYStart = format.getImageableY();         double xRatio = pWidth / cWidth;         double yRatio = pHeight / cHeight;         Graphics2D g2 = (Graphics2D) g;         g2.translate(pXStart, pYStart);         g2.scale(xRatio, yRatio);         comp.paint(g2);         return Printable.PAGE_EXISTS;     } }

                  • 6. Re: Code throwing Null exceptoin
                    hphanjra-JavaNet

                    package FinCal;

                    /*
                    *  mc.btnNewButton_2.addActionListener(new ActionListener() {
                       public void actionPerformed(ActionEvent arg0) {
                       
                           PrinterJob pjob = PrinterJob.getPrinterJob();
                           PageFormat preformat = pjob.defaultPage();
                           preformat.setOrientation(PageFormat.LANDSCAPE);
                           PageFormat postformat = pjob.pageDialog(preformat);
                           //If user does not hit cancel then print.
                           if (preformat != postformat) {
                               //Set print component
                               pjob.setPrintable(new Printer((Component)frmMain), postformat);
                               if (pjob.printDialog()) {
                                 try {  pjob.print(); }catch(Exception E) {}
                               }
                           }
                             
                       
                       }
                      });

                    */
                    import java.awt.Component;
                    import java.awt.Dimension;
                    import java.awt.Graphics;
                    import java.awt.Graphics2D;
                    import java.awt.event.ActionEvent;
                    import java.awt.event.ActionListener;
                    import java.awt.print.PageFormat;
                    import java.awt.print.Printable;
                    import java.awt.print.PrinterException;
                    import java.awt.print.PrinterJob;

                    public  class Printer implements Printable {
                        final Component comp;

                        public Printer(Component comp){
                            this.comp = comp;
                        }

                        @Override
                        public int print(Graphics g, PageFormat format, int page_index)
                                throws PrinterException {
                            if (page_index > 0) {
                                return Printable.NO_SUCH_PAGE;
                            }

                            // get the bounds of the component
                            Dimension dim = comp.getSize();
                            double cHeight = dim.getHeight();
                            double cWidth = dim.getWidth();

                            // get the bounds of the printable area
                            double pHeight = format.getImageableHeight();
                            double pWidth = format.getImageableWidth();

                            double pXStart = format.getImageableX();
                            double pYStart = format.getImageableY();

                            double xRatio = pWidth / cWidth;
                            double yRatio = pHeight / cHeight;

                            Graphics2D g2 = (Graphics2D) g;
                            g2.translate(pXStart, pYStart);
                            g2.scale(xRatio, yRatio);
                            comp.paint(g2);

                            return Printable.PAGE_EXISTS;
                        }
                    }

                     

                    package FinCal;

                    import javax.swing.border.*;
                    import javax.swing.event.*;
                    import javax.swing.table.*;

                    import java.awt.event.*;

                    import javax.swing.*;

                    import java.util.*;
                    import java.util.List;
                    import java.awt.*;
                      
                    public class JTextAreaTableExample extends JFrame {
                     
                      public JTextAreaTableExample() {
                        super( "JTextAreaTableExample Example" );
                      
                        DefaultTableModel dtm = new DefaultTableModel() {
                           // make first cell uneditable
                           public boolean isCellEditable(int row, int column)
                           {
                              return !(column == 0);
                           }
                          
                        };
                     
                        dtm.setDataVector(new Object[][]{{ "JTextArea1", "This is a testnon long linesn" ,"col2 value"},
                                                         { "JTextArea2",  "Hello world"  ,"col3 valu"}},
                                          new Object[]{ "String","JTextArea","COL2"});
                                         
                        JTable table = new JTable(dtm);
                        table.getColumn("JTextArea").setCellRenderer(new TextAreaRenderer("DA"));
                        // table.getColumn("JTextArea").setCellEditor(new TextAreaEditor("FF"));
                         
                        
                        table.getColumn("COL2").setCellRenderer(new TextAreaRenderer("SD"));
                       // table.getColumn("COL2").setCellEditor(new TextAreaEditor("FF"));
                       
                     
                        table.setRowHeight(80);
                        JScrollPane scroll = new JScrollPane(table);
                        getContentPane().add(scroll);
                     
                        setSize( 800, 700 );
                        setVisible(true);
                      }
                     
                      public static void main(String[] args) {
                        JTextAreaTableExample frame = new JTextAreaTableExample();
                        frame.addWindowListener(new WindowAdapter() {
                          public void windowClosing(WindowEvent e) {
                            System.exit(0);
                          }
                        });
                      }
                    }
                      
                    class TextAreaRenderer extends JScrollPane implements TableCellRenderer
                    {
                       JTextArea textarea;
                       JLabel jlabel ;
                       CalPanel cp1 = new CalPanel();
                       TextAreaRenderer(){
                       
                       }
                       public TextAreaRenderer(String t) {
                       
                          textarea = new JTextArea();
                          textarea.setLineWrap(true);
                          textarea.setWrapStyleWord(true);
                          jlabel = new JLabel("fdsf");
                         

                          textarea.setBorder(new TitledBorder(t));
                          textarea.add(jlabel);
                          System.out.println("JJJJJJJJ");
                         // getViewport().add(textarea);
                         // jlabel.setBounds(10, 20, 46, 14);
                         // cp.add(jlabel,10,20,46,14);
                       
                         // getViewport().add(jlabel);
                         
                         
                           }
                     
                       public Component getTableCellRendererComponent(JTable table, Object value,
                                                      boolean isSelected, boolean hasFocus,
                                                      int row, int column)
                       {
                    // System.out.println("6 Exiting value --->"+value);
                       //System.exit(9);
                    //   CalPanel cp1 = new CalPanel();
                      // cp1.setdate("DS"); 
                    // cp1.setdate("sddd");
                          //      cp1.setdate1("dddd");
                      String datevalue = value+"";
                      String monthvalue = (CalendarProgram1.currentMonth+1)+"";
                     
                      try {
                      int dateD = Integer.valueOf(value+"");
                      if (dateD < 10) {
                       datevalue = "0"+datevalue ;
                      } 
                      }catch(Exception kkk) {}
                     
                      try {
                       int dateM = Integer.valueOf(monthvalue+"");
                       if (dateM < 10) {
                        monthvalue = "0"+monthvalue ;
                       } 
                       }catch(Exception kkk) {}
                     
                     
                       String mydate = CalendarProgram1.currentYear+"-"+monthvalue+"-"+datevalue;
                       CalendarProgram1.viewingDay = mydate;
                      String vs = null;
                    /////  System.out.println(mydate+"Shift information  searching for------------------->"+CalendarProgram1.getDataByDate(mydate));

                      List mydlist = CalendarProgram1.getDataByDate(mydate);
                     
                         cp1.label.setText(" ");
                         cp1.label_1.setText(" ");
                         cp1.label_2.setText(" ");
                         cp1.label_3.setText(" ");
                         cp1.label_4.setText(" ");
                         cp1.label_5.setText(" ");
                        
                      cp1.lblNewLabel.setText(" ");
                        
                         if ((value != null) ) {
                      
                       if (mydlist  !=null) { 
                       if ( !CalendarProgram1.CandiView ){
                       

                        try { cp1.lblNewLabel.setText(mydlist.get(0)+"("+mydlist.get(1)+")"+mydlist.get(2)+":"+mydlist.get(3)+":"+mydlist.get(4)+""); }catch(Exception jj) {}
                           //cp1.label.setText(mydlist.get(12)+"("+mydlist.get(13)+")"+mydlist.get(2)+":"+mydlist.get(3)+"");
                           try {  
                            cp1.label_1.setText(mydlist.get(11)+"("+mydlist.get(12)+")"+mydlist.get(13)+":"+mydlist.get(14)+":"+mydlist.get(15)+""); }catch(Exception jj) {}
                        try { cp1.label_2.setText(mydlist.get(22)+"("+mydlist.get(23)+")"+mydlist.get(24)+":"+mydlist.get(25)+":"+mydlist.get(26)+"");   }catch(Exception jj) {}
                        try { cp1.label_3.setText(mydlist.get(33)+"("+mydlist.get(34)+")"+mydlist.get(35)+":"+mydlist.get(36)+":"+mydlist.get(37)+"");   }catch(Exception jj) {}
                        try { cp1.label_4.setText(mydlist.get(44)+"("+mydlist.get(45)+")"+mydlist.get(46)+":"+mydlist.get(47)+":"+mydlist.get(48)+"");   }catch(Exception jj) {}
                        try { cp1.label_5.setText(mydlist.get(55)+"("+mydlist.get(56)+")"+mydlist.get(57)+":"+mydlist.get(58)+":"+mydlist.get(59)+"");   }catch(Exception jj) {}
                        try { cp1.label.setText(mydlist.get(66)+"("+mydlist.get(67)+")"+mydlist.get(68)+":"+mydlist.get(69)+":"+mydlist.get(70)+"");   }catch(Exception jj) {}

                       
                    }
                       
                        //      cp1.label_2.setText(mydlist.get(3)+"");
                    //     cp1.label_3.setText(mydlist.get(4)+"");
                    //cp1.label_4.setText(mydlist.get(5)+""); 

                        for ( int j=0;j<mydlist.size();j++) {
                        System.out.print(" "+ mydlist.get(j));
                      
                        if ( (j != 0) && ((j+1) % CalendarProgram1.daySize == 0)) {
                            
                      /////       System.out.println(   "  In Painter " +mydate);
                        }
                          }
                       }
                           
                       cp1.lblHarin.setText("My Test");
                      
                       
                      
                      // cp1.lblNewLabel.setText(CalendarProgram1.allContent[0][0][0]);

                         // cp1.lblHarin.setText(" "+value);

                         
                         
                         
                         
                         
                          cp1.setdate(" "+value);
                         
                             getViewport().add(cp1);    

                      }else {
                       cp1.setBackground(Color.LIGHT_GRAY);
                       getViewport().remove(cp1);
                      
                      }
                       
                      /* Component cell = getTableCellRendererComponent(
                                      table, value, isSelected, hasFocus, row, column);
                    */  
                      //   setBackground(table.getBackground());
                      /* 
                        if (isSelected) {
                             setForeground(table.getSelectionForeground());
                             setBackground(table.getSelectionBackground());
                             textarea.setForeground(table.getSelectionForeground());
                             textarea.setBackground(table.getSelectionBackground());
                            // textarea.setBackground(Color.blue);
                          } else {
                             setForeground(table.getForeground());
                             setBackground(table.getBackground());
                             textarea.setForeground(table.getForeground());
                             textarea.setBackground(table.getBackground());
                          }
                     
                          try{textarea.setText((String) value);
                           }catch(Exception ex) {
                          
                           };
                         //  textarea.add(cell);  
                         
                          textarea.setCaretPosition(0);
                         
                          */
                      revalidate();
                          return this;
                       }
                    }
                     
                    class TextAreaEditor implements TableCellEditor {
                       protected JScrollPane scrollpane;
                       protected JTextArea textarea;
                       CalPanel cs = new CalPanel();
                       public TextAreaEditor() {
                       // super(new JCheckBox());
                       }

                       public TextAreaEditor(String tt ) {
                       // super(new JCheckBox());
                         // this.cancelCellEditing();
                       
                          scrollpane = new JScrollPane();
                          textarea = new JTextArea(); 
                          textarea.setLineWrap(true);
                          textarea.setWrapStyleWord(true);
                          JButton jb = new JButton("KKK");
                          jb.setVisible(true);

                          JPanel panel = new JPanel();
                          panel.setBackground(Color.BLACK);
                          panel.add( new JButton("SDFDFDSF"));
                          panel.setVisible(true);
                         
                         
                          //textarea.add(jb);
                    //     textarea.revalidate();
                                ////     textarea.add(cs);
                         
                          textarea.setBorder(new TitledBorder(tt));
                        //  scrollpane.getViewport().add(textarea);
                        //  scrollpane.revalidate();
                      //    textarea.revalidate();
                       }
                     
                       public Component getTableCellEditorComponent(JTable table, Object value,
                                                       boolean isSelected, int row, int column) {
                         // textarea.setText((String) value);

                      //   String mvalue = Integer.toString(value);
                       try { textarea.setText( (String) value); } catch(Exception e) { System.out.println(e);}
                       System.out.println("ssssssssssssssssssss");
                        
                          return scrollpane;
                       }
                     
                       public Object getCellEditorValue() {
                          return textarea.getText();
                       }
                    @Override
                    public void addCellEditorListener(CellEditorListener arg0) {
                    // TODO Auto-generated method stub

                    }
                    @Override
                    public void cancelCellEditing() {
                    // TODO Auto-generated method stub

                    }
                    @Override
                    public boolean isCellEditable(EventObject arg0) {
                    // TODO Auto-generated method stub
                    return false;
                    }
                    @Override
                    public void removeCellEditorListener(CellEditorListener arg0) {
                    // TODO Auto-generated method stub

                    }
                    @Override
                    public boolean shouldSelectCell(EventObject arg0) {
                    // TODO Auto-generated method stub
                    return false;
                    }
                    @Override
                    public boolean stopCellEditing() {
                    // TODO Auto-generated method stub
                    return false;
                    }
                    }

                    /*
                    class CalPanel extends JPanel {



                      JLabel lblHarin = new JLabel("Main Class Hardsafdsf "
                       + "dfaddsfdsaf in");
                    JLabel lblNewLabel = new JLabel("New label");

                    public CalPanel() {
                      setLayout(null);
                     
                      lblHarin.setBounds(10, 11, 146, 14);
                      add(lblHarin);

                      lblNewLabel.setBounds(10, 24, 112, 14);
                      add(lblNewLabel);
                     
                      JFormattedTextField formattedTextField = new JFormattedTextField();
                      formattedTextField.setBounds(10, 43, 112, 20);
                      add(formattedTextField);

                    }
                    public void setdate(String str) {
                      lblHarin.setText(str);
                    }
                    public void setdate1(String str) {
                      lblNewLabel.setText(str);
                    }

                    }

                    */

                     

                     

                     

                    package FinCal;

                    import javax.swing.JPanel;
                    import javax.swing.border.EtchedBorder;
                    import java.awt.Color;
                    import javax.swing.JButton;
                    import java.awt.Rectangle;
                    import java.awt.event.MouseAdapter;
                    import java.awt.event.MouseEvent;
                    import java.awt.event.ActionListener;
                    import java.awt.event.ActionEvent;
                    import javax.swing.JComboBox;
                    import javax.swing.JRadioButton;

                    public class MainControl extends JPanel {
                    JButton btnNewButton = new JButton("Calendar");
                    JButton btnNewClient = new JButton("New Client"); 
                    JButton btnNewCandidate = new JButton("New Candidate");
                    JButton btnNewButton_1 = new JButton("Shifts");
                        JButton btnAssigments = new JButton("Assigments");

                    JButton btnNewButton_2 = new JButton("Print");
                        /* Create the panel.
                      */
                    public MainControl() {

                      addMouseListener(new MouseAdapter() {
                       @Override
                       public void mouseClicked(MouseEvent arg0) {
                        System.out.println(" Enter Client");
                       }
                      });
                      setBounds(new Rectangle(0, 0, 800, 80));
                      setBorder(new EtchedBorder(EtchedBorder.RAISED, Color.CYAN, Color.BLACK));
                     

                      btnNewClient.setBounds(376, 7, 89, 23);
                      btnNewClient.addMouseListener(new MouseAdapter() {
                       @Override
                       public void mouseClicked(MouseEvent arg0) {
                        System.out.println(" in Main Control Enter Client button pressed");
                       }
                      });
                      setLayout(null);
                     

                      btnNewButton.addMouseListener(new MouseAdapter() {
                       @Override
                       public void mouseClicked(MouseEvent arg0) {
                        System.out.println("In Main Control Calendar button pressed");
                       }
                      });
                      btnNewButton.setBounds(376, 43, 89, 23);
                      add(btnNewButton);
                      add(btnNewClient);
                     

                      btnNewCandidate.addMouseListener(new MouseAdapter() {
                       @Override
                       public void mouseClicked(MouseEvent arg0) {
                       }
                      });
                      btnNewCandidate.setBounds(253, 7, 105, 23);
                      add(btnNewCandidate);
                      btnNewButton_1.addMouseListener(new MouseAdapter() {
                       @Override
                       public void mouseClicked(MouseEvent arg0) {
                        System.out.println(" Shifts in Main");
                       }
                      });
                      btnNewButton_1.setBounds(253, 43, 112, 23);
                     
                      add(btnNewButton_1);
                      btnAssigments.addMouseListener(new MouseAdapter() {
                       @Override
                       public void mouseClicked(MouseEvent arg0) {
                       }
                      });
                      btnAssigments.setBounds(475, 7, 89, 23);
                     
                      add(btnAssigments);
                     

                      btnNewButton_2.addActionListener(new ActionListener() {
                       public void actionPerformed(ActionEvent arg0) {
                       
                       }
                      });
                      btnNewButton_2.setBounds(10, 22, 89, 23);
                      add(btnNewButton_2);
                     
                      JComboBox comboBox = new JComboBox();
                      comboBox.setBounds(506, 44, 105, 20);
                      add(comboBox);
                     
                      JRadioButton rdbtnCandiview = new JRadioButton("CandiView");
                      rdbtnCandiview.addActionListener(new ActionListener() {
                       public void actionPerformed(ActionEvent arg0) {
                        if ( rdbtnCandiview.isSelected()) {
                         CalendarProgram1.CandiView = true;
                        }else CalendarProgram1.CandiView = false;
                       }
                      });
                      rdbtnCandiview.setBounds(627, 7, 109, 23);
                      add(rdbtnCandiview);

                    }
                    }

                    • 7. Re: Code throwing Null exceptoin
                      hphanjra-JavaNet

                      /*

                      Dashboard learning as swing classes excercise.

                      Build a standalone gui to assign task


                      delete from cts_cus
                      delete from cts_shifts
                      delete from assignment

                      select * from cts_cus
                      select * from cts_shifts
                      select * from assignment

                      select day,fac_name,candi_type,  f_7_3 ,f_3_11,f_11_7
                      , f1, f2, f3,  f4,  f5,  f6,  f7,  f8, f9,  f10
                      from mytest_vw
                      order by 1,2,3

                      select * from assignment_status

                      select * from  cts_candi

                      drop table cts_candi

                      create table cts_candi
                      (fname   varchar(10),
                      lname  varchar(10),
                      type   varchar(20)
                      )

                      drop table cts_shifts
                      go
                      CREATE TABLE [dbo].[cts_shifts](
                          [Id] int IDENTITY(1,1) NOT NULL PRIMARY KEY,
                      [day] [varchar](20) ,
                      [fac_name] [varchar](20) NULL,
                      [candi_type] [varchar](10) NULL,
                      [f_7_3] int NULL,
                      [f_3_11] int NULL,
                      [f_11_7] int NULL,
                      [f_7_3_who] varchar(20) NULL,
                      [f_3_11_who] varchar(20) NULL,
                      [f_11_7_who] varchar(20) NULL,
                      [f_7_3_ti] varchar(20) NULL,
                      [f_7_3_to] varchar(10) NULL,
                      [f_3_11_ti] varchar(10) NULL,
                      [f_3_11_to] varchar(10) NULL,
                      [f_11_7_ti] varchar(10) NULL,
                      [f_11_7_to] varchar(10) NULL,
                          comments     varchar(30)
                      )
                      drop view assignment_status

                      create view assignment_status
                      as
                        select b.day as bday,b.fac_name as bfac_name, b.candi_type as bcandi_type,a.day,a.fac_name,canditype,count(*) as booked
                        ,whod
                        from mytest_vw b
                        LEFT OUTER JOIN assignment a
                        ON
                         a.day = b.day
                        and a.fac_name = b.fac_name
                        and a.canditype = b.candi_type
                        group by  b.day,b.fac_name, b.candi_type,a.day,a.fac_name,canditype,whod

                      insert into assignment values('2018-01-31','Hudson','333-222-1111','LPN','7-3','HAWA','777-222-6665','this is a commment',null)

                      insert into assignment values('2017-12-06','sss','333-222-1111','CNA','7-3','HAWA','777-222-6665','this is a commment',null)
                      go
                      insert into assignment values('2017-12-11','sss','333-222-1111','CNA','7-3','HTRW','777-222-6665','this is a commment',null)
                      go
                      insert into assignment values('2017-12-11','sss','333-222-1111','CNA','7-3','TTTT','777-222-6665','this is a commment',null)
                      go
                      insert into assignment values('2018-01-06','BISHOP','333-222-1111','LPN','7-3','HTRW','777-222-6665','this is a commment',null)

                      drop table assignment
                      go
                      create table assignment
                      (day  varchar(10),
                      fac_name varchar(10),
                      fac_ph1 varchar(13),
                      canditype  varchar(10),
                      shift  varchar(10),
                      whod  varchar(10),
                      who_ph  varchar(13),
                      comments varchar(30),
                      cancelled  varchar(10)
                      )

                       

                       

                       

                      drop view mytest_vw
                      go
                      create view mytest_vw
                      as
                      select day,fac_name,candi_type, f_7_3 as f_7_3
                      , f_3_11 as f_3_11
                      , f_11_7 as f_11_7 
                      ,'f1' as f1
                      ,'f2' as f2
                      ,'f3' as f3
                      ,'f4' as f4
                      ,'f5' as f5
                      ,'f6' as f6
                      ,'f7' as f7
                      ,'f8' as f8
                      ,'f9' as f9
                      ,'f10' as f10
                      from cts_shifts
                      --group by day,fac_name,candi_type

                       

                      select * from mytest_vw

                      delete from cts_cus
                      go
                      delete from cts_shifts

                      drop table cts_cus
                      go
                      CREATE TABLE [dbo].[cts_cus](
                      [day] [varchar](10) NULL,
                      [fac_name] [varchar](20) NULL,
                      [last_name] [varchar](10) NULL
                      ) ON [PRIMARY]

                      drop table cts_shifts
                      go

                      drop table cts_shifts
                      go
                      CREATE TABLE [dbo].[cts_shifts](
                          [Id] int IDENTITY(1,1) NOT NULL PRIMARY KEY,
                      [day] [varchar](20) ,
                      [fac_name] [varchar](20) NULL,
                      [candi_type] [varchar](10) NULL,
                      [f_7_3] int NULL,
                      [f_3_11] int NULL,
                      [f_11_7] int NULL
                      )

                      */

                      package FinCal;

                      import javafx.scene.layout.Border;

                      import javax.swing.*;
                      import javax.swing.border.TitledBorder;
                      import javax.swing.event.*;
                      import javax.swing.table.*;
                      import javax.swing.text.DefaultCaret;
                      import javax.swing.text.SimpleAttributeSet;
                      import javax.swing.text.StyleConstants;
                      import javax.swing.text.StyledDocument;

                      import java.awt.*;
                      import java.util.List;
                      import java.util.*;
                      import java.awt.event.*;
                      import java.awt.print.PageFormat;
                      import java.awt.print.PrinterException;
                      import java.awt.print.PrinterJob;
                      import java.sql.Connection;
                      import java.sql.DriverManager;
                      import java.sql.PreparedStatement;
                      import java.sql.ResultSet;
                      import java.sql.SQLException;
                      import java.util.*;
                      import java.util.Timer;
                      import java.awt.*;

                      import javax.swing.*;

                       

                      public class CalendarProgram1{
                       
                       
                      static JTextArea textarea;
                          static JLabel lblMonth, lblYear;
                          static JButton btnPrev, btnNext;
                          static JTable tblCalendar;
                          static JComboBox cmbYear;
                          static JFrame frmMain;
                          static Container pane;
                          static DefaultTableModel mtblCalendar; //Table model
                          static JScrollPane stblCalendar; //The scrollpane
                          static JPanel pnlCalendar;
                          static int realYear, realMonth, realDay, currentYear, currentMonth;
                          static String[][][] mytext= new String [4][4][100];
                         /// static CalPanel calPanel = new CalPanel();
                          static boolean alreadyOpened = false;
                          static CalFrame cf = null; //new CalFrame();
                          static ClientPanel cpanel = null;
                          static CandiPanel candipanel = null;
                          static  Assignment  assignment = null ; //new Assignment();
                         static Shifts shifts = null;
                        
                          static MiscDatabaseTasks mis = new MiscDatabaseTasks();
                          static String[][][] allContent = new String[2][3000][3000];
                          static int I = 2;
                          static int J = 3;
                          static HashMap AllShifts = new HashMap();
                         
                          static Map<String, List<String>> hmShifts = new HashMap<String, List<String>>();
                          static Map<String, List<String>> assignmentStatus = new HashMap<String, List<String>>();

                         
                          static int daySize = 11;
                      static String viewingDay = " ";
                      static String selectedPeriod = " ";

                      static boolean seven = false;
                      static boolean three  = false;
                      static boolean eleven = false;
                      static String sftWhere = " ";


                      // -------------------
                      static boolean CandiView = false;


                         
                          public static void printTemp() {
                           for (int i=0;i<I;i++) {
                            for (int j=0;j<J;j++) {
                              System.out.print(" allContent["+i+"]["+j+"]"+allContent[i][j][0]); 
                            }
                            System.out.println();
                           }
                          }
                          public static void popluateTemp() {
                              String name = "Har";
                              String title = "CN";
                              String hired = "YES";
                           for (int i=0;i<I;i++) {
                            for (int j=0;j<J;j++) {
                              allContent[i][j][0]= name+" "+i+" "+j; 
                            }
                           
                           }
                            
                          }
                          public static void main (String args[]){
                          

                             candipanel = new CandiPanel();
                           popluateTemp();
                           printTemp();
                           //System.exit(0);
                          
                           Connection con = null;
                          
                             mytext[0][0][0] = "har";
                             mytext[0][0][2] = "Rav";
                            
                              try {UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());}
                              catch (ClassNotFoundException e) {}
                              catch (InstantiationException e) {}
                              catch (IllegalAccessException e) {}
                              catch (UnsupportedLookAndFeelException e) {}
                             
                              //Prepare frame
                              frmMain = new JFrame ("Gestionnaire de clients"); //Create frame
                             

                       

                             
                           //   frmMain.setSize(330, 375); //Set size to 400x400 pixels
                               frmMain.setSize(1050,950); //Set size to 400x400 pixels
                              frmMain.setResizable(true);
                              pane = frmMain.getContentPane(); //Get content pane
                              pane.setLayout(null); //Apply null layout
                              frmMain.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //Close when X is clicked
                             
                              //Create controls
                              lblMonth = new JLabel ("January");
                              lblYear = new JLabel ("Change year:");
                              cmbYear = new JComboBox();
                             // btnPrev = new JButton ("&lt;&lt;Next");
                              //btnNext = new JButton ("&gt;&gt;");
                              btnPrev = new JButton ("Prev");
                              btnNext = new JButton ("Next");
                             
                              mtblCalendar = new DefaultTableModel(){public boolean isCellEditable(int rowIndex, int mColIndex){return false;}};
                              tblCalendar = new JTable(mtblCalendar);
                             
                            //  tblCalendar.getColumn("").setCellRenderer(new TextAreaRenderer());
                              //tblCalendar.getColumn("FD").setCellRenderer(cellRenderer);

                              stblCalendar = new JScrollPane(tblCalendar);
                              pnlCalendar = new JPanel(null);
                              ClientForm cform = new  ClientForm(" fdsf","ss");
                        
                              //Set border
                              pnlCalendar.setBorder(BorderFactory.createTitledBorder("Calendar"));
                             
                              //Register action listeners
                              btnPrev.addActionListener(new btnPrev_Action());
                              btnNext.addActionListener(new btnNext_Action());
                              cmbYear.addActionListener(new cmbYear_Action());
                             
                              //Add controls to pane
                              MainControl mc = new MainControl();
                             // pane.add(pnlCalendar);
                          //   mc.setBounds(0, 0, 100, 200);

                             
                        mc.btnNewButton_2.addActionListener(new ActionListener() {
                         public void actionPerformed(ActionEvent arg0) {
                         
                             PrinterJob pjob = PrinterJob.getPrinterJob();
                             PageFormat preformat = pjob.defaultPage();
                             preformat.setOrientation(PageFormat.LANDSCAPE);
                             PageFormat postformat = pjob.pageDialog(preformat);
                             //If user does not hit cancel then print.
                             if (preformat != postformat) {
                                 //Set print component
                                 pjob.setPrintable(new Printer((Component)frmMain), postformat);
                                 if (pjob.printDialog()) {
                                   try {  pjob.print(); }catch(Exception E) {}
                                 }
                             }
                               
                         
                         }
                        });

                             mc.setVisible(true);
                             pane.add(mc);
                        mc.btnNewButton_1.addMouseListener(new MouseAdapter() {
                         @Override
                         public void mouseClicked(MouseEvent arg0) {
                          System.out.println(" Shifts in Calendar");

                           try {  pane.remove(pnlCalendar);
                           }catch(Exception e) {}
                           try {  
                           pane.remove(cpanel);
                           }catch(Exception e) {}

                           try { 
                            pane.remove(cpanel);
                            }catch(Exception e) {}
                           try {  
                           pane.remove(cpanel);
                           }catch(Exception e) {}
                           try {  
                            //pane.remove(shifts);
                            }catch(Exception e) {}

                           try {  
                            pane.remove(candipanel);
                            }catch(Exception e) {}
                       
                           try {  
                            pane.remove(assignment);
                            }catch(Exception e) {}
                       
                            pane.revalidate();
                            pane.repaint(); 
                          
                            shifts = new Shifts();
                            getFacilities("ssss,fss  ");
                            // pane.remove(mc);
                          //  cpanel = new ClientPanel();
                            shifts.setVisible(true);
                              pane.add(shifts);
                            //  System.out.println(" shifti panel added");
                             pane.revalidate();
                             pane.repaint();
                            
                         }
                        });
                       
                             mc.btnNewCandidate.addMouseListener(new MouseAdapter() {
                         @Override
                         public void mouseClicked(MouseEvent arg0) {
                         
                          System.out.println(" Enter Candidate button pressed");
                         
                           try {  pane.remove(pnlCalendar);
                           }catch(Exception e) {}
                           try {  
                           pane.remove(cpanel);
                           }catch(Exception e) {}

                           try { 
                            pane.remove(cpanel);
                            }catch(Exception e) {}
                           try {  
                           pane.remove(cpanel);
                           }catch(Exception e) {}
                           try {  
                            pane.remove(shifts);
                            }catch(Exception e) {}

                           try {  
                            pane.remove(candipanel);
                            }catch(Exception e) {}
                       
                           try {  
                            pane.remove(assignment);
                            }catch(Exception e) {}
                       
                            pane.revalidate();
                            pane.repaint(); 

                            candipanel = new CandiPanel();
                            // pane.remove(mc);
                          //  cpanel = new ClientPanel();
                           
                            candipanel.btnNewButton_1.addMouseListener(new MouseAdapter() {
                            @Override
                            public void mouseClicked(MouseEvent arg0) {
                             System.out.println(" Inserting candidate ---------->");
                             insertCandi();
                            }
                           });
                           
                            candipanel.setVisible(true);
                              pane.add(candipanel);
                              System.out.println(" Candi panel added");
                             pane.revalidate();
                             pane.repaint(); 
                            
                         }
                        });
                            
                          
                               
                        mc.btnAssigments.addMouseListener(new MouseAdapter() {
                         @Override
                         public void mouseClicked(MouseEvent arg0) {
                          
                           getAssignmentStatus();
                           try {  pane.remove(pnlCalendar);
                            }catch(Exception e) {}
                           try {  
                           pane.remove(cpanel);
                           }catch(Exception e) {}

                           try { 
                            //pane.remove(cpanel);
                            }catch(Exception e) {}
                           try {  
                           pane.remove(cpanel);
                           }catch(Exception e) {}
                           try {  
                            pane.remove(shifts);
                            }catch(Exception e) {}

                           try {  
                            pane.remove(candipanel);
                            }catch(Exception e) {}
                           try {  
                            pane.remove(assignment);     
                            }catch(Exception e) {}
                       
                            pane.revalidate();
                            pane.repaint(); 

                          //  getFacilities("ssss,fss  ");
                            assignment = new Assignment();
                           
                      /*
                            assignment.faclist.removeAllItems();
                            for (int t = 0; t <  shifts.comboBox_4.getItemCount(); t++)
                            {
                             assignment.faclist.addItem( shifts.comboBox_4.getItemAt(t));
                           
                            }
                            */
                            System.out.println(" ((((((((((((((((((((((((((-->"+assignmentStatus.size());
                            Set <String> ke=  assignmentStatus.keySet();
                            for (int t = 0; t <  assignmentStatus.keySet().size(); t++)
                            {
                             System.out.println(" ((((((((((((((((((((((((((-->"+assignmentStatus.get(t));
                          //   System.out.println(" ((((((((((((((((((((((((((-->"+ke.);
                             

                             
                            }
                           
                            assignment.bookDate.addActionListener(new ActionListener() {
                            public void actionPerformed(ActionEvent arg0) {
                            
                             //System.out.println("  Action listner for book date -------------------->");
                                   System.out.println(" AddItem Listner ss Select ITem is ---->"+ke.size()); 
                                   selectedPeriod  = (String)assignment.bookDate.getSelectedItem();
                                System.out.println( " refreshing...: "+  selectedPeriod);
                                 // refreshAssignmentDate(ke);   
                                  refreshAssignment(ke);
                            
                            }
                           });
                           
                           assignment.shift_detail.addActionListener(new ActionListener() {
                            public void actionPerformed(ActionEvent arg0) {
                                              
                               refreshShiftDetail();

                             System.out.println( " seven -->"+seven);
                            }
                           });
                           
                          
                           assignment.btnSave.addActionListener(new ActionListener() {
                            public void actionPerformed(ActionEvent arg0) {
                             System.out.println(" btn save clicked");
                             updateShift();
                              refreshShiftDetail();
                            
                            
                            }
                           });
                          
                           
                      /*
                                assignment.bookDate.addItemListener(new ItemListener() {
                            public void itemStateChanged(ItemEvent arg0) {
                                  System.out.println(" AddItem Listner ss Select ITem is ---->"+ke.size()); 
                                  selectedPeriod  = (String)assignment.bookDate.getSelectedItem();
                               System.out.println( " refreshing...: "+  selectedPeriod);
                                // refreshAssignmentDate(ke);   
                                 refreshAssignment(ke);

                            }

                                });
                                */
                         
                               refreshAssignmentDate(ke);
                          //  refreshAssignment(ke);
                           
                            /*
                               Iterator<String> it = ke.iterator();
                           
                               while(it.hasNext()){
                                String item = it.next();
                                  System.out.println("KKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD"+assignmentStatus);
                                  assignment.bookDate.addItem(item);
                            List ks = assignmentStatus.get(item);
                                System.out.println(item+"LIST    KKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD"+ks);
                              
                                  System.out.println("@@@@@@@@@@@@@@@@@@@@@@@@@"+ks.size());
                                   
                                 
                                 
                                Object[] numbers = ks.toArray();
                                System.out.println("@@@@@@@@@@@@@@@@@@@@@@@@@"+numbers[1]);
                                String tstring = " ";
                                int itr = ks.size();
                                for (int y=1;y<ks.size();) {          
                                 System.out.println("*************************"+numbers[y-1]);
                                 System.out.println("*************************"+numbers[y]);
                                 System.out.println("*************************"+numbers[y+1]);
                                 System.out.println("*************************"+numbers[y+2]);
                                 System.out.println("*************************"+numbers[y+3]);
                                 System.out.println("*************************"+numbers[y+4]);
                                 System.out.println("*************************"+numbers[y+5]);
                                 System.out.println("*************************"+numbers[y+6]);
                                 System.out.println("*************************"+numbers[y+7]);
                                 System.out.println("*************************"+numbers[y+8]);          
                                 String this_item=  numbers[y-1]
                                 + " "+numbers[y]
                                  +numbers[y+1] +numbers[y+5]; 
                                
                              System.out.println(item  + " : "+  selectedPeriod);
                             
                             assignment.shift_detail.addItem(this_item);          
                             y=y+11;         
                                }           
                                  assignment.whoD.addItem(ks.get(1));
                      //           assignment.shift_detail.addItem(ks);           
                               }

                              
                               */
                           
                          //  cpanel.setVisible(true);
                          //assignment.faclist.add(  shifts.comboBox_4.getComponents());
                            // pane.remove(mc);
                              pane.add(assignment);
                             pane.revalidate();
                             pane.repaint();   
                         }
                        });

                       
                             mc.btnNewClient.addMouseListener(new MouseAdapter() {
                         @Override
                         public void mouseClicked(MouseEvent arg0) {   
                          System.out.println(" Enter Client button pressed");

                        
                             try {  pane.remove(pnlCalendar);
                              }catch(Exception e) {}
                             try {  
                             pane.remove(cpanel);
                             }catch(Exception e) {}

                             try { 
                              //pane.remove(cpanel);
                              }catch(Exception e) {}
                             try {  
                             pane.remove(cpanel);
                             }catch(Exception e) {}
                             try {  
                              pane.remove(shifts);
                              }catch(Exception e) {}

                             try {  
                              pane.remove(candipanel);
                             
                             }catch(Exception e) {}
                         
                              
                              try {  
                               pane.remove(assignment);

                             }catch(Exception e) {}
                          
                             
                              pane.revalidate();
                              pane.repaint(); 

                        
                              cpanel = new ClientPanel();
                              cpanel.setVisible(true);
                              // pane.remove(mc);
                                pane.add(cpanel);
                               pane.revalidate();
                               pane.repaint(); 
                        
                        
                        
                        
                        
                        
                         }
                        });
                       
                        mc.btnNewButton.addMouseListener(new MouseAdapter() {
                         @Override
                         public void mouseClicked(MouseEvent arg0) {
                         
                          System.out.println(" calender is clicked");
                         
                                 getAssignmentStatus();
                                 getAllFac();
                           try {  pane.remove(pnlCalendar);
                            }catch(Exception e) {}
                           try {  
                           pane.remove(cpanel);
                           }catch(Exception e) {}

                           try {  pane.remove(cpanel);
                            }catch(Exception e) {}
                           try {  
                           pane.remove(cpanel);
                           }catch(Exception e) {}
                           try {  
                            pane.remove(shifts);
                            }catch(Exception e) {}

                           try {  
                            pane.remove(candipanel);
                            }catch(Exception e) {}
                           try {  
                            pane.remove(assignment);
                            }catch(Exception e) {}
                       
                       
                            pane.revalidate();
                            pane.repaint(); 

                          try {
                          
                           System.out.println("Calling getCal INfo -------------------------------------*********************");
                          // getCalInfo();
                         
                          }catch(Exception e) {System.out.println(e);
                          }
                         
                          System.out.println(" Calendar button pressed");
                           pane.add(pnlCalendar);
                          // pane.remove(mc);
                           pane.revalidate();
                           pane.repaint();
                         }
                        });
                            pane.revalidate();
                               
                              pnlCalendar.add(lblMonth);
                              pnlCalendar.add(lblYear);
                              pnlCalendar.add(cmbYear);
                              pnlCalendar.add(btnPrev);
                              pnlCalendar.add(btnNext);
                              pnlCalendar.add(stblCalendar);
                            
                             
                              tblCalendar.addMouseListener(new java.awt.event.MouseAdapter() {
                                       JInterFrame jif = null;
                                   //    DayDetail dd = null ;
                               boolean isAlreadyOneClick = false;
                                  public void mouseClicked(java.awt.event.MouseEvent evt) {
                                      int row = tblCalendar.rowAtPoint(evt.getPoint());
                                      int col = tblCalendar.columnAtPoint(evt.getPoint());
                                      System.out.println("evt"+evt);
                                     ///-- if(evt.getClickCount()==1){
                                          if (row >= 0 && col >= 0) {
                                          System.out.println(evt.getClickCount()+"Row clicked -->"+row + " Column clicked -->"+col); //......; //

                                         //  }
                                        }
                                     
                                   
                                          System.out.println("double click");
                                         
                                          if (isAlreadyOneClick  && !alreadyOpened  ) {
                                          //    if (isAlreadyOneClick  ) {

                                           //   jif = new JInterFrame();
                                          //    dd = new DayDetail();
                                         
                                             // jif.setVisible(true);
                                              cf = new CalFrame();
                                           
                                              cf.addWindowListener(new java.awt.event.WindowAdapter() {

                                         @Override
                                         public void windowClosing(java.awt.event.WindowEvent arg0) {
                                           System.out.println(arg0.WINDOW_CLOSING+")))))))))))))))))))))))))))))))))))))))))))))))))))))"+evt);
                                           if (arg0.WINDOW_CLOSING == 201) {
                                           alreadyOpened = false ;
                                           }
                                          
                                         }
                                        });
                                             
                                             JButton jsb = new JButton("KK");
                                             cf.getContentPane().add(jsb);
                                             cf.textArea_1.setText("viewingDay "+viewingDay+"\n line 2");
                                            // cf.textArea_1.setText("fkkkk");
                                             cf.textArea_1.append("fdsfds");
                                           
                                 
                                             String hh = realYear+"*"+ realMonth+"*"+ realDay+"*"+ currentYear+"*"+ currentMonth;
                                           // try {Thread.sleep(1000);}catch(Exception gs) {}
                                            //List tpd = CalendarProgram1.getDataByDate(viewingDay);
                                            List tpd = CalendarProgram1.getShiftDataByDate(viewingDay);
                                           
                                            System.out.println(viewingDay +"VIEWING >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> --------->"+ tpd);
                                           
                                              String itemString = " ";
                                            int item_length = 11;
                                            if (tpd !=null){
                                            for(int i=1;i<=tpd.size();i++){
                                             itemString = itemString + tpd.get(i-1)+ " ";
                                          
                                             if ( (i % item_length) == 0) {
                                             System.out.println(i+" Appending ----->>"+itemString);
                                                  cf.textArea_1.append(" \n "+itemString);    
                                                  itemString = " ";
                                             }
                                            }
                                            }else {
                                             System.out.println("  ***************   No Data found             **************"+viewingDay);
                                            }
                                           
                                         

                                       
                                             cf.setVisible(true);
                                             cf.setAlwaysOnTop(true);
                                             alreadyOpened = true;
                                      
                                          
                                            frmMain.setVisible(true);
                                            frmMain.setFocusable(false);
                                      
                                          //  frmMain.getContentPane().add(cf,BorderLayout.WEST);
                                            frmMain.revalidate();
                                              isAlreadyOneClick = false;
                                          } else {
                                              isAlreadyOneClick = true;
                                              Timer t = new Timer("doubleclickTimer", false);
                                              t.schedule(new TimerTask() {

                                                  @Override
                                                  public void run() {
                                                      isAlreadyOneClick = false;
                                                  }
                                              }, 500);
                                          }     
                                         
                                         
                                              
                                  }
                                 
                                    
                                 
                                 
                              });

                              //Set bounds
                              //pnlCalendar.setBounds(0, 0, 320, 335);
                              pnlCalendar.setBounds(0, 0, 1000, 900);
                              lblMonth.setBounds(160-lblMonth.getPreferredSize().width/2, 90, 100, 25);
                              lblYear.setBounds(10, 875, 80, 20);
                              cmbYear.setBounds(230, 875, 80, 20);
                      //        btnPrev.setBounds(10, 25, 90, 25); // Original
                      //        btnNext.setBounds(210, 25, 90, 25);
                              btnPrev.setBounds(10, 90, 90, 25);
                              btnNext.setBounds(210, 90, 90, 25);
                             
                           //   stblCalendar.setBounds(10, 50, 300, 250);
                              stblCalendar.setBounds(10, 120, 980, 740);
                             
                              //Make frame visible
                              frmMain.setResizable(false);
                              frmMain.setVisible(true);
                             
                              //Get real month/year
                              GregorianCalendar cal = new GregorianCalendar(); //Create calendar
                              realDay = cal.get(GregorianCalendar.DAY_OF_MONTH); //Get day
                              realMonth = cal.get(GregorianCalendar.MONTH); //Get month
                              realYear = cal.get(GregorianCalendar.YEAR); //Get year
                              currentMonth = realMonth; //Match month and year
                              currentYear = realYear;
                             
                              //Add headers
                              String[] headers = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"}; //All headers
                              for (int i=0; i<7; i++){
                                  mtblCalendar.addColumn(headers[i]);
                              }
                              getAllFac();
                              tblCalendar.getParent().setBackground(tblCalendar.getBackground()); //Set background
                             
                              //No resize/reorder
                              tblCalendar.getTableHeader().setResizingAllowed(false);
                              tblCalendar.getTableHeader().setReorderingAllowed(false);
                             
                              //Single cell selection
                              tblCalendar.setColumnSelectionAllowed(true);
                              tblCalendar.setRowSelectionAllowed(true);
                              tblCalendar.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
                             
                              //Set row/column count
                              tblCalendar.setRowHeight(58);
                              tblCalendar.setRowMargin(1);
                              mtblCalendar.setColumnCount(7);
                              mtblCalendar.setRowCount(6);
                             
                              //Populate table
                              for (int i=realYear-100; i<=realYear+100; i++){
                                  cmbYear.addItem(String.valueOf(i));
                              }
                             
                              //Refresh calendar
                              refreshCalendar (realMonth, realYear); //Refresh calendar
                              System.out.println("kjkkkkkkkkkkkkkkkkkkkkkk-->"+tblCalendar.getColumnName(0));
                              }
                         
                      public static void refreshShiftDetail() {
                         String sft = assignment.shift_detail.getSelectedItem()+" ";
                        System.out.println("  Selected item at shift_detail --->"+sft);
                        String[] arrsft = sft.split(",");
                      try {      System.out.println(" string 0"+arrsft[0] + "string 1"+arrsft[1] + "string 2"+arrsft[2]
                          + "string 3"+arrsft[3] + "string 4"+arrsft[4]
                            + "string 5"+arrsft[5] );
                        if ( arrsft[3].trim().equals("0")) {seven = false;}else seven = true;
                        if ( arrsft[4].trim().equals("0")) {three = false;}else three = true;
                        if ( arrsft[5].trim().equals("0")) {eleven = false;}else eleven = true;
                        sftWhere = arrsft[2];
                        String candiTyp = arrsft[1].trim() ;
                         popluateCandi("dd",candiTyp);
                        setCandi();
                        
                       
                         
                        
                      }catch(Exception d) {}

                      }
                          public static void updateShift() {
                          
                           String sft_1 = assignment.CandicomboBox.getSelectedItem() + " ";
                           String sft_2 = assignment.candicomboBox_1.getSelectedItem() + " ";
                           String sft_3 = assignment.candicomboBox_2.getSelectedItem() + " ";
                          
                           String sft_set =  " set ";
                             sft_set = sft_set + " f_7_3_who = '"+sft_1+"'";
                             sft_set = sft_set + ", f_3_11_who = '"+sft_2+"'";
                             sft_set = sft_set + ", f_11_7_who = '"+sft_3+"'";
                          
                          
                              String sft_where = " where  Id = ";
                                 sft_where = sft_where + " '"+sftWhere +"'";
                             
                           Connection dbConnection = null;
                             ResultSet resultSet = null;
                             ArrayList<String> names = new ArrayList<String>();

                             try {
                                 dbConnection = mis.getDatabaseConnection();
                                 String query =
                                         "update cts_shifts" +
                                          sft_set +
                                          sft_where ;
                                        

                                 System.out.println("Sql------>>****"+query);
                                  dbConnection.prepareStatement(query).execute();
                                  //dbConnection.prepareStatement(query).executeQuery();
                                 // dbConnection.commit();

                             } catch (Exception e) {
                            e.printStackTrace();
                               getAllFac();
                               
                             } finally {                          
                             }
                          
                          }
                          public static void refreshAssignmentDate(Set ke) {
                           try {
                           /// Thread.sleep(200);
                           }catch(Exception ee) {}
                           Iterator<String> it = ke.iterator();
                      System.out.println(" -------------->>>>"+ke.size());

                            while(it.hasNext()){
                             String item = it.next();
                               System.out.println("Book Date    --------------KKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD"+assignmentStatus);
                                  assignment.bookDate.addItem(item);

                            }   
                          }
                         
                          public static void setCandi() {
                              if (!seven) assignment.CandicomboBox.setEnabled(false) ;else  assignment.CandicomboBox.setEnabled(true);
                              if (!three) assignment.candicomboBox_1.setEnabled(false) ;else  assignment.candicomboBox_1.setEnabled(true);
                              if (!eleven) assignment.candicomboBox_2.setEnabled(false) ;else  assignment.candicomboBox_2.setEnabled(true);
                          
                          }
                          public static void refreshAssignment(Set ke) {
                          
                            try {
                           /// Thread.sleep(200);
                           }catch(Exception ee) {}
                           Iterator<String> it = ke.iterator();
                      System.out.println(" ke size-------------->>>>"+ke.size());

                      //assignment.shift_detail.removeAll();
                      //System.out.println(" -------------->>>>"+ assignment.shift_detail.list());
                      //assignment.shift_detail = new JComboBox();
                      JComboBox t_shift_detail = new JComboBox();
                      assignment.shift_detail.removeAll();
                            while(it.hasNext()){
                             String item = it.next();
                      //        System.out.println("KKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD"+assignmentStatus);
                            //      assignment.bookDate.addItem(item);
                         List ks = assignmentStatus.get(item);
                        //     System.out.println(item+"LIST    KKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD"+ks);
                           
                      //      System.out.println("@@@@@@@@@@@@@@@@@@@@@@@@@"+ks.size());
                                
                             Object[] numbers = ks.toArray();
                      //       System.out.println("@@@@@@@@@@@@@@@@@@@@@@@@@"+numbers[1]);
                             String tstring = " ";
                             int itr = ks.size();
                            
                             for (int y=1;y<ks.size();) {
                             
                                 System.out.println("*************************"+numbers[y-1]);
                              System.out.println("*************************"+numbers[y]);
                              System.out.println("*************************"+numbers[y+1]);
                              System.out.println("*************************"+numbers[y+2]);
                              System.out.println("*************************"+numbers[y+3]);
                              System.out.println("*************************"+numbers[y+4]);
                              System.out.println("*************************"+numbers[y+5]);
                              System.out.println("*************************"+numbers[y+6]);
                              System.out.println("*************************"+numbers[y+7]);
                              System.out.println("*************************"+numbers[y+8]); 
                        
                              String this_item=  numbers[y-1]
                              + " "+numbers[y]
                               +numbers[y+1] +numbers[y+2]
                               +numbers[y+3] +numbers[y+4]
                               +numbers[y+5] +numbers[y+6]
                                 ; 

                             

                             
                              if (selectedPeriod != null)   { 
                             if(item.trim() == selectedPeriod.trim()) {   
                              t_shift_detail.addItem(this_item);
                             // assignment.shift_detail.addItem(this_item); 
                            // assignment.shift_detail.setSelectedItem(this_item);
                         //     System.out.println(selectedPeriod  + " adding   shift detail: "+ item  + "  <<-adding item->> "+this_item + "  ===>>>"+assignment.shift_detail.getSelectedItem());       
                               
                             }else {
                           // System.out.println( selectedPeriod  + " removing o detail: "+ item +"<<-removing item->> "+this_item  );
                              assignment.shift_detail.removeItem(this_item);
                             }
                         
                             }
                          y=y+11;         
                             } // end for  
                            //  assignment.whoD.addItem(ks.get(1));
                      //       assignment.shift_detail.addItem(ks);

                            
                             
                            }//end while

                            assignment.shift_detail.removeAllItems();
                            for (int t = 0; t < t_shift_detail.getItemCount(); t++)
                            {
                             assignment.shift_detail.addItem(t_shift_detail.getItemAt(t));
                            }

                            setCandi();    
                            System.out.println(  " Selected item  ===>>>"+assignment.shift_detail.getSelectedItem());
                            popluateCandi("dd","DT");
                           
                          }
                         
                          public static java.util.List<String> populateArr(String str) {    
                           java.util.List<String> list = new ArrayList<String>(Arrays.asList(str.split(" , ")));
                           return list;
                          }
                         
                          public static void getFacilities(String str) {
                           java.util.List<String> myList = populateArr(str);
                           System.out.println(str + "insert shifts ---------------------------------->"+myList.size() + " 0 -->"+myList.get(0));
                           Connection dbConnection = null;
                             ResultSet resultSet = null;
                             ArrayList<String> names = new ArrayList<String>();

                             try {
                                 dbConnection = mis.getDatabaseConnection();
                                 String query =
                                         " select * from cts_cus " +
                                          " ";
                        System.out.println("Sql- get facilitys----->>****"+query);
                               resultSet =   dbConnection.prepareStatement(query).executeQuery();
                               //   dbConnection.commit();
                               while (resultSet.next()) {
                                   shifts.comboBox_4.addItem(resultSet.getString(2));
                                   shifts.comboBox_5.addItem(resultSet.getString(2));
                                  
                               }

                             } catch (Exception e) {
                               e.printStackTrace();
                             } finally {                          
                             }
                          }   

                          public static String getCandiInfo() {
                         
                            String str =  candipanel.fname.getText();
                                 str = str  + " , " + candipanel.lname.getText() + " , "+candipanel.candiTypecomboBox.getSelectedItem() ;
                            return str;
                          }
                         
                          public static void insertCandi() {
                           System.out.println(" inserting candidate ");
                         
                              String str = getCandiInfo();
                          
                           java.util.List<String> myList = populateArr(str);
                           System.out.println(str + " insert shifts ---------------------------------->"+myList.size() + " 0 -->"+myList.get(0));
                           Connection dbConnection = null;
                             ResultSet resultSet = null;
                             ArrayList<String> names = new ArrayList<String>();

                             try {
                                 dbConnection = mis.getDatabaseConnection();
                                 String query =
                                         "insert into cts_candi" +
                                         " values ( '" + myList.get(0)+"' , '"+ myList.get(1)+"','"+   myList.get(2)  +"'  )";

                                 System.out.println("Sql------>>****"+query);
                                  dbConnection.prepareStatement(query).executeQuery();
                                  dbConnection.commit();

                             } catch (Exception e) {
                            e.printStackTrace();
                               getAllFac();
                               
                             } finally {                          
                             }
                          
                          }
                          public static void insertShifts(String str) {
                           java.util.List<String> myList = populateArr(str);
                           System.out.println(str + " insert shifts ---------------------------------->"+myList.size() + " 0 -->"+myList.get(0));
                           Connection dbConnection = null;
                             ResultSet resultSet = null;
                             ArrayList<String> names = new ArrayList<String>();

                             try {
                                 dbConnection = mis.getDatabaseConnection();
                                
                                 int S = 0;
                                 int T = 0;
                                 int E = 0;
                                 try {S = Integer.parseInt(myList.get(2).trim());}catch(Exception e) {};
                                 try {T = Integer.parseInt(myList.get(3).trim());}catch(Exception e) {};
                                 try {E = Integer.parseInt(myList.get(4).trim());}catch(Exception e) {};
                                           
                                 int B = 0;
                                 if (S>T && S> E) {
                                  B = S;
                                 }else if ( T > E) {
                                  B = T;
                                 }else B = E;
                        
                                
                                 System.out.println(" Inserting shifts --------%%%%%%%%%%%%%%%%%%%%%%%%%%%%%--------------->"+B);
                                 for (int i=0;i< B;i++) {
                                  int Si,Ti,Ei = 0;
                                  if (S != 0){S = S-1; Si =1;}else Si=0;
                                  if (T != 0){T = T-1; Ti =1;}else Ti=0;
                                  if (E != 0){E = E-1; Ei =1;}else Ei=0;
                                 
                                 String query =
                                         "insert into cts_shifts(day,fac_name,candi_type,f_7_3,f_3_11,f_11_7)" +
                                         " values ( '" + myList.get(5)+"', '"+ myList.get(0)+"','"+myList.get(1)+"','"+Si+"','"+Ti+ "'"
                                         +" , '"+Ei+ "'"+" )";

                                 System.out.println("Sql------>>****"+query);
                               //   dbConnection.prepareStatement(query).executeQuery();
                                  dbConnection.createStatement().execute(query);
                                 }
                                 // dbConnection.commit();

                             } catch (Exception e) {
                            e.printStackTrace();
                               getAllFac();
                               
                             } finally {                          
                             }
                             getAssignmentStatus();
                           //  refreshShiftDetail();
                            
                          }   

                         
                         
                         
                         
                          public static List getShiftDataByDate(String dt) {    
                           //System.out.println("DDDDDDDDDDDDDDDDDAAAAAAAAAAAAAAATE____________>"+dt);
                          // dt = "2017-12-11";
                           String myd = " ";
                          
                            List mydlist = assignmentStatus.get(dt);

                        ///System.out.println(" hm data"+hm);
                       
                          // System.out.println(" fExiting value --->  getDataByDate -->"+dt + "   data is -->");
                          
                          try {
                           for ( int j=0;j<mydlist.size();j++) {
                            //System.out.print(" "+ mydlist.get(j));
                            if ( (j != 0) && ((j+1) % daySize == 0)) {
                            // System.out.println();
                            }
                           }
                          }catch(Exception kk) {
                           ///System.out.println(" kkk --->"+kk);
                          }

                           return mydlist;
                          }
                         
                          public static void getAssignmentStatus() {
                           Connection dbConnection = null;
                              ResultSet resultSet = null;
                         try {     
                           dbConnection = mis.getDatabaseConnection();
                                String query =
                                //"select bday,bfac_name,bcandi_type,day,fac_name,canditype,booked,whod from assignment_status order by 1,2,3" ;
                                "select day,fac_name,candi_type,Id,f_7_3,f_3_11,f_11_7,f_7_3_who,f_3_11_who,f_7_3_ti,f_7_3_to "
                                + "from cts_shifts order by 1,2,3" ;
                                  System.out.println("Sql getAssignmentStatus------>>****"+query);     
                             ResultSet rs = dbConnection.prepareStatement(query).executeQuery();
                             List<String> values = new ArrayList<String>();
                         
                             String key1 = " ";
                          
                             //values.add("Value 1");
                             // values.add("Value 2");
                           //hm.put("Key1", values);

                           // to get the arraylist
                          // System.out.println(hm.get("key1"));
                          
                          
                           String predat = " ";
                           boolean firsttime = true;
                           String dat ="";
                          String fac = "" ;// rs.getString(2);
                          String candi = "";//rs.getString(3);            
                          String  s7 = "";//rs.getString(4);
                         String  s11 = "";//rs.getString(4);
                        String  s3 = "";//rs.getString(4);
                        String f1 = "";
                        String f2 = "";
                        String f3 = "";
                        String f4 = "";
                        String f5 = "";
                        String f6 = "";
                       
                       
                           while (rs.next()) {
                                dat = rs.getString(1);
                                fac = rs.getString(2) +" , ";
                                candi = rs.getString(3) +" , ";
                                s7 = rs.getString(4) +" , ";
                                s3 = rs.getString(5)+" , ";
                                s11 = rs.getString(6)+" , ";
                             f1 = rs.getString(7)+" , ";
                           f2 = rs.getString(8)+" , ";
                            f3 = rs.getString(9);
                           f4 = rs.getString(10);
                           /*  f5 = rs.getString(11);
                            f6 = rs.getString(12);
                           
                         */      
                            //  AllShifts.put(dat+fac +","+candi+",",fac +","+candi+","+s7);
                                   // shifts.comboBox_5.addItem(resultSet.getString(2));
                            // System.out.println(AllShifts.size()+" Hastable ----------->"+AllShifts);
                          //   System.out.println("Is -->>"+dat +" = "+ predat);  
                             if(!dat.equals(predat)) {
                           //   System.out.println ("   Key TOKEN IS CHANGED");
                              predat = dat;        
                              if(!firsttime) {
                               assignmentStatus.put(key1, values);          
                        
                           //       System.out.println(key1+"<--key1  values"+values);   
                                 
                                   values = new ArrayList<String>();
                                     key1 = dat;       
                                   values.add(fac);
                                   values.add(candi);
                                   values.add(s7);
                               values.add(s3);
                              values.add(s11);
                            
                             
                             values.add(f1);
                             values.add(f2);
                             values.add(f3);
                             values.add(f4);
                             values.add(f5);
                             values.add(f6);
                             
                                
                                 }else {
                                 key1 = dat;       
                                 values.add(fac);
                                 values.add(candi);
                                 values.add(s7);
                              values.add(s3);
                              values.add(s11);
                          values.add(f1);
                             values.add(f2);
                             values.add(f3);
                             values.add(f4);
                             values.add(f5);
                             values.add(f6);
                            
                          //    System.out.println("This is FIRST time ----> so inserting Map key1"+key1);
                                  firsttime = false;
                                 
                                 }
                              }else {
                              key1 = dat;

                             values.add(fac);
                             values.add(candi);
                           values.add(s7);
                          values.add(s3);
                              values.add(s11);
                             values.add(f1);
                             values.add(f2);
                             values.add(f3);
                             values.add(f4);
                             values.add(f5);
                             values.add(f6);             
                           //         System.out.println (key1+" NOT CHANGED    TOKEN  "+candi);                   
                              }
                                }      
                             //Last one
                           assignmentStatus.put(key1, values);            
                         //     System.out.println(key1+"<--key1  values"+values); 
                        //     System.out.println( "   My Hastable ----------->"+assignmentStatus);   
                      //    System.out.println(assignmentStatus.keySet());
                             Set se = assignmentStatus.keySet();
                          
                             for (int i=0;i<assignmentStatus.size();i++) {
                            //System.out.println("Key Set ----->"+assignmentStatus.keySet()); 
                           
                             }
                            
                           // getDataByDate("DDDDDDD");
                            }catch(Exception ex) {         
                             System.out.println("ex)"+ex); ex.printStackTrace();         
                            }
                      }

                         
                         
                          public static void getAllFac() {
                              Connection dbConnection = null;
                                 ResultSet resultSet = null;
                            try {     
                              dbConnection = mis.getDatabaseConnection();
                                   String query =
                                          " select day,fac_name,candi_type, sum( f_7_3) as f_7_3,  sum(f_3_11) as f_3_11 ,  sum(f_11_7) as f_11_7 "
                                         +" , f1, f2, f3,  f4,  f5,  f6,  f7,  f8, f9,  f10 "
                      +" from mytest_vw "
                      + " group by  day,fac_name,candi_type , f1, f2, f3,  f4,  f5,  f6,  f7,  f8, f9,  f10"
                      +" order by day "
                                        ;
                         System.out.println("Sql------>>****"+query);
                              
                                ResultSet rs = dbConnection.prepareStatement(query).executeQuery();
                          //    AllShifts = new HashMap();
                            

                       

                              List<String> values = new ArrayList<String>();
                             String key1 = " ";
                             
                              //values.add("Value 1");
                             // values.add("Value 2");
                              //hm.put("Key1", values);

                              // to get the arraylist
                         /////////////////////////  System.out.println("*****************************************"+hm.get("key1"));
                             
                             
                              String predat = " ";
                              boolean firsttime = true;
                              String dat ="";
                           String fac = "" ;// rs.getString(2);
                           String candi = "";//rs.getString(3);            
                           String  s7 = "";//rs.getString(4);
                          String  s11 = "";//rs.getString(4);
                         String  s3 = "";//rs.getString(4);
                        String f1 = "";
                        String f2 = "";
                        String f3 = "";
                        String f4 = "";
                        String f5 = "";
                        String f6 = "";
                       
                        
                              while (rs.next()) {
                                   dat = rs.getString(1);
                                   fac = rs.getString(2);
                                   candi = rs.getString(3);
                                   s7 = rs.getString(4);
                                   s3 = rs.getString(5);
                                   s11 = rs.getString(6);
                                f1 = rs.getString(7);
                               f2 = rs.getString(8);
                               f3 = rs.getString(9);
                               f4 = rs.getString(10);
                               f5 = rs.getString(11);
                               f6 = rs.getString(12);
                              
                                  
                               //  AllShifts.put(dat+fac +","+candi+",",fac +","+candi+","+s7);
                                      // shifts.comboBox_5.addItem(resultSet.getString(2));
                               // System.out.println(AllShifts.size()+" Hastable ----------->"+AllShifts);
                                   System.out.println("Is -->>"+dat +" = "+ predat);  

                                   if(!dat.equals(predat)) {
                                 System.out.println ("   Key TOKEN IS CHANGED");
                                 predat = dat;        
                                 if(!firsttime) {
                                 hmShifts.put(key1, values);          
                           
                                     System.out.println(key1+"<--key1  values"+values);                  
                                     values = new ArrayList<String>();
                                      key1 = dat;       
                                      values.add(fac);
                                      values.add(candi);
                                //   values.add("S7");
                                  values.add(s7);
                                        values.add(s3);
                                      values.add(s11);
                                      values.add(f1);
                                      values.add(f2);
                                      values.add(f3);
                                      values.add(f4);
                                      values.add(f5);
                                      values.add(f6);
                                    }else {
                                      key1 = dat;       
                                      values.add(fac);
                                      values.add(candi);
                                   //          values.add("S7");
                                       values.add(s7);
                                      values.add(s3);
                                      values.add(s11);
                                      values.add(f1);
                                      values.add(f2);
                                      values.add(f3);
                                      values.add(f4);
                                      values.add(f5);
                                      values.add(f6);       
                                      System.out.println("This is FIRST time ----> so inserting Map key1"+key1);
                                     firsttime = false;
                                    }
                                 }else {
                                 key1 = dat;

                                values.add(fac);
                                values.add(candi);
                           //   values.add("S7");
                                values.add(s7);
                             values.add(s3);
                              values.add(s11);
                             values.add(f1);
                                values.add(f2);
                                values.add(f3);
                                values.add(f4);
                                values.add(f5);
                                values.add(f6);
                                     
                                       System.out.println (key1+" NOT CHANGED    TOKEN  "+candi);           
                                
                                 }
                               
                               
                                   }      
                                //Last one
                              hmShifts.put(key1, values);          
                       
                              System.out.println(key1+"<--key1  values"+values); 
                             
                             
                             
                                System.out.println( "   My Hastable ----------->"+hmShifts);   
                            
                          System.out.println("hm"+hmShifts.keySet());
                             Set se = hmShifts.keySet();
                            
                           ////////////////////////  assignment.bookDate.add
                            /*
                                for (int i=0;i<hm.size();i++) {
                               System.out.println(hm.keySet());        
                                }
                                */         
                              // getDataByDate("DDDDDDD");
                               }catch(Exception ex) {         
                                System.out.println("ex)"+ex); ex.printStackTrace();         
                             }
                          }
                         
                         

                         
                          public static List getDataByDate(String dt) {    
                           //System.out.println("DDDDDDDDDDDDDDDDDAAAAAAAAAAAAAAATE____________>"+dt);
                          // dt = "2017-12-11";
                           String myd = " ";
                          
                            List mydlist = hmShifts.get(dt);

                        ///System.out.println(" hm data"+hm);
                       
                          // System.out.println(" fExiting value --->  getDataByDate -->"+dt + "   data is -->");
                          
                          try {
                           for ( int j=0;j<mydlist.size();j++) {
                            //System.out.print(" "+ mydlist.get(j));
                            if ( (j != 0) && ((j+1) % daySize == 0)) {
                            // System.out.println();
                            }
                           }
                          }catch(Exception kk) {
                           ///System.out.println(" kkk --->"+kk);
                          }

                           return mydlist;
                          }
                         
                         
                          public static void popluateCandi(String zip,String type) {
                          
                           String mtype = type;
                           Connection dbConnection = null;
                             ResultSet resultSet = null;
                             ArrayList<String> names = new ArrayList<String>();
                             try {
                                 dbConnection = mis.getDatabaseConnection();
                                 String query =
                                         "SELECT fname + ' , ' + lname " +
                                         "FROM cts_candi " +
                                         "where type = '"+mtype+"'";
                      ///          System.out.println(" popluateCandi ------------------------------------------>"+mtype);
                                 resultSet = dbConnection.prepareStatement(query).executeQuery();

                                 assignment.CandicomboBox.removeAllItems();
                                 assignment.candicomboBox_1.removeAllItems();
                                 assignment.candicomboBox_2.removeAllItems();
                                
                      //System.out.println(" CandicoboBox emptied ---->"+assignment.CandicomboBox.getItemCount());
                                 while (resultSet.next()) {
                                 String rslt =  resultSet.getString(1)+"";
                                  assignment.CandicomboBox.addItem(rslt);
                                  assignment.candicomboBox_1.addItem(rslt);
                                  assignment.candicomboBox_2.addItem(rslt);
                                  //   names.add(resultSet.getString(1));
                                  //    System.out.println(" name--> "+resultSet.getString(1)+"");
                                //      System.out.println(" CandicoboBox Item count now ---->"+assignment.CandicomboBox.getItemCount());
                                     // break;
                                 }
                             } catch (Exception e) {
                                  e.printStackTrace();
                             } finally {                          
                             }    
                          
                          }
                         
                         
                          public static void insertCust(String str) {
                           java.util.List<String> myList = populateArr(str);
                           System.out.println(str + ":List items ---------------------------------->"+myList.size() + " 0 -->"+myList.get(0));
                           Connection dbConnection = null;
                             ResultSet resultSet = null;
                             ArrayList<String> names = new ArrayList<String>();

                             try {
                                 dbConnection = mis.getDatabaseConnection();
                                 String query =
                                         "insert into cts_cus" +
                                         " values ('20000', '" + myList.get(0)+"','"+myList.get(1)+"'"+
                                         " )";

                                  dbConnection.prepareStatement(query).executeQuery();
                                  dbConnection.commit();

                             } catch (Exception e) {
                               e.printStackTrace();
                             } finally {                          
                             }
                          }   
                          public static void getCalInfo () {
                           //insertCust("Rav dd , Kaur fs ");
                          // populateArr("Harinder, Singh");
                              Connection dbConnection = null;
                                 ResultSet resultSet = null;
                                 ArrayList<String> names = new ArrayList<String>();
                                 try {
                                     dbConnection = mis.getDatabaseConnection();
                                     String query =
                                             "SELECT first_name + ' , ' + last_name " +
                                             "FROM cts_cus " +
                                             "ORDER BY last_name";

                                     resultSet = dbConnection.prepareStatement(query).executeQuery();
                                     while (resultSet.next()) {
                                         names.add(resultSet.getString(1));
                                         System.out.println(" name--> "+names.get(0));
                                         break;
                                     }
                                 } catch (Exception e) {
                      //               e.printStackTrace();
                                 } finally {                          
                                 }        
                          }       
                          public static String getCalText(int year, int month, int day ) {
                           String str = " ";
                           str = mytext[0][0][0];
                           return str ;
                          }
                          public static void refreshCalendar(int month, int year){
                              //Variables
                              String[] months =  {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"};
                              int nod, som; //Number Of Days, Start Of Month
                             
                              //Allow/disallow buttons
                              btnPrev.setEnabled(true);
                              btnNext.setEnabled(true);
                              if (month == 0 && year <= realYear-10){btnPrev.setEnabled(false);} //Too early
                              if (month == 11 && year >= realYear+100){btnNext.setEnabled(false);} //Too late
                              lblMonth.setText(months[month]); //Refresh the month label (at the top)
                              lblMonth.setBounds(160-lblMonth.getPreferredSize().width/2, 90, 180, 25); //Re-align label with calendar
                              cmbYear.setSelectedItem(String.valueOf(year)); //Select the correct year in the combo box
                             
                              //Clear table
                              for (int i=0; i<6; i++){
                                  for (int j=0; j<7; j++){
                                      mtblCalendar.setValueAt(null, i, j);
                                  }
                              }
                             
                              //Get first day of month and number of days
                              GregorianCalendar cal = new GregorianCalendar(year, month, 1);
                              nod = cal.getActualMaximum(GregorianCalendar.DAY_OF_MONTH);
                              som = cal.get(GregorianCalendar.DAY_OF_WEEK);
                             
                              //Draw calendar
                              for (int i=1; i<=nod; i++){
                                  int row = new Integer((i+som-2)/7);
                                  int column  =  (i+som-2)%7;
                          //        mtblCalendar.setValueAt(i+"\n\n sS" +"\t"+"html><div style=\"text-align:center\">Math fdsfsdafdsa,<br>Class1</div></html>"
                           //         + " \n jj", row, column);
                                  JPanel jp = new JPanel();
                                   jp.setBounds(0, 10, 10, 10);
                                  mtblCalendar.setValueAt( Integer.toString(i), row, column);

                               
                                  //   mtblCalendar.setValueAt(i, row, column);
                                  //  System.out.println("year :  "+year+" month -->"+month+" : row -->"+row +" : column-->"+column +"  i-->"+i  );
                                 
                              }       
                             
                             
                              //Apply renderers
                      //       tblCalendar.setDefaultRenderer(tblCalendar.getColumnClass(0), new PlusMinusCellRenderer());
                           //   tblCalendar.setDefaultRenderer(tblCalendar.getColumnClass(0), new tblCalendarRenderer());
                              tblCalendar.getColumn("Mon").setCellRenderer(new TextAreaRenderer("SF"));
                              tblCalendar.getColumn("Tue").setCellRenderer(new TextAreaRenderer("SF"));
                              tblCalendar.getColumn("Wed").setCellRenderer(new TextAreaRenderer("SF"));
                              tblCalendar.getColumn("Thu").setCellRenderer(new TextAreaRenderer("SF"));
                              tblCalendar.getColumn("Fri").setCellRenderer(new TextAreaRenderer("SF"));
                              tblCalendar.getColumn("Sat").setCellRenderer(new TextAreaRenderer("SF"));
                              tblCalendar.getColumn("Sun").setCellRenderer(new TextAreaRenderer("SF"));
                             
                            //  tblCalendar.getColumn("Mon").setCellEditor(new TextAreaEditor("FS"));
                            //  tblCalendar.getColumn("Mon").setCellEditor(new TextAreaEditor("F2"));
                             
                             // TextAreaEditor tx = new TextAreaEditor("F3");
                                
                              Label lb = new Label("DFDF");
                          //    tx.get(lb);
                             
                          //    tblCalendar.getColumn("Mon").setCellEditor(new TextAreaEditor("F3"));
                             
                              
                             
                              System.out.println("-------------------"+tblCalendar.getCellRenderer(0, 1));
                              tblCalendar.setRowHeight(120);
                              tblCalendar.setRowMargin(1);
                              tblCalendar.revalidate();
                          }
                          /*
                          static class PlusMinusCellRenderer extends JPanel implements TableCellRenderer {
                              public Component getTableCellRendererComponent(
                                                  final JTable table, Object value,
                                                  boolean isSelected, boolean hasFocus,
                                                  int row, int column) {
                                      this.add( new JTextField( value.toString()  ) );
                                      this.add( new JButton("+"));
                                      this.add( new JButton("-"));
                                      return this;
                              }
                      }
                          */
                          static class tblCalendarRenderer extends   DefaultTableCellRenderer{
                          
                          
                              public Component getTableCellRendererComponent (JTable table, Object value, boolean selected, boolean focused, int row, int column){
                        
                                  value = value + " \r DD";
                                   
                               super.getTableCellRendererComponent(table, value, selected, focused, row, column);   
                               
                               
                                  ///    String toReturn = "<html><b>" + (String)value + "</b></html>"; 
                               System.out.println(" 3 Exiting "+value);
                            System.exit(9);
                              
                                
                                //  table.setValueAt("Harin", row, column);
                           //   javax.swing.border.Border padding = BorderFactory.createEmptyBorder(0, 10, 0, 10);

                           //      Component cell = getTableCellRendererComponent(
                             //          table, value, selected, focused, row, column);
                                 
                              ///    String valueD = (String)value;
                                 
                                //  table.getColumn("Notes").setCellRenderer(new TableCellRenderer());
                                 
                                //  textarea = new JTextArea(2,20);
                                //  table.add(textarea);
                              //    textarea.setLineWrap(true);
                            //      textarea.setWrapStyleWord(true);

                         //          textarea.setText(valueD);
                      //             textarea.setWrapStyleWord(true);
                          //         textarea.setLineWrap(true);
                          //         DefaultCaret caret = (DefaultCaret) textarea.getCaret();
                         //          caret.setUpdatePolicy(DefaultCaret.NEVER_UPDATE);
                              
                                 // value = "{<html><i><u><b>HTML</b></u></i></html>" ;
                                
                            //       setBorder(BorderFactory.createCompoundBorder(getBorder(), padding));
                            //       this.add(new JLabel("SSD"));
                                  
                                  if (selected) {
                                       this.setBackground(Color.lightGray);
                                     }

                                  if (column == 0 || column == 6){ //Week-end
                                          setBackground(new Color(255, 220, 220));
                                         // table.setValueAt("SSS", 0, 2);
                                  }
                                  else{ //Week
                                          setBackground(new Color(255, 255, 255));
                                  }
                                  if (value != null){
                                   try {
                                      if (Integer.parseInt(value.toString()) == realDay && currentMonth == realMonth && currentYear == realYear){
                                       //Today
                                   //      setBackground(new Color(220, 220, 255));
                                           setBackground(new Color(220, 220, 255));
                                          }
                                   }catch(Exception ee) {
                                   
                                   
                                   }
                                  
                                  } {
                                   
                                  }
                                
                                  if (selected) {
                               setBackground(Color.lightGray);
                                   }
                                 
                               //   setBorder(null);
                               //   setForeground(Color.black);

                                 
                                  if (selected) {
                                     // cell.getCsetBackground(Color.OPAQUE); //(and perhaps other cells) are selected
                                  }

                                  if (focused) {
                                      // this cell is the anchor and the table has the focus
                                  }

                                  // Configure the component with the specified value
                                //  setText(value.toString());

                                  // Set tool tip if desired
                                //  setToolTipText((String)value);

                                  // Since the renderer is a component, return itself
                                 validate();
                                               return this;
                             //     return new JLabel(toReturn); 

                              } 
                          }
                         
                         
                          static class btnPrev_Action implements ActionListener{
                              public void actionPerformed (ActionEvent e){
                                  if (currentMonth == 0){ //Back one year
                                      currentMonth = 11;
                                      currentYear -= 1;
                                  }
                                  else{ //Back one month
                                      currentMonth -= 1;
                                  }
                                  refreshCalendar(currentMonth, currentYear);
                              }
                          }
                         
                          static class btnNext_Action implements ActionListener{
                              public void actionPerformed (ActionEvent e){
                                  if (currentMonth == 11){ //Foward one year
                                      currentMonth = 0;
                                      currentYear += 1;
                                  }
                                  else{ //Foward one month
                                      currentMonth += 1;
                                  }
                                  refreshCalendar(currentMonth, currentYear);
                              }
                          }
                          static class cmbYear_Action implements ActionListener{
                              public void actionPerformed (ActionEvent e){
                                  if (cmbYear.getSelectedItem() != null){
                                      String b = cmbYear.getSelectedItem().toString();
                                      currentYear = Integer.parseInt(b);
                                      refreshCalendar(currentMonth, currentYear);
                                  }
                              }
                          }
                      }

                      class MiscDatabaseTasks {

                          private static Map<String, String> config = null;
                          //creates the connection string
                          private static Map<String, String> getDatabaseConfig() {
                              if (config == null) {
                                  Map<String, String> props = new HashMap<String, String>();
                                  props.put("database.class", "net.sourceforge.jtds.jdbc.Driver");
                                  props.put("database.url",
                                          "jdbc:jtds:sqlserver://PSCWS10049;databaseName=cts_dashboard_dev");
                                  props.put("database.username", "cts_dashboard_user");
                                  props.put("database.password", "Nomura_123");
                                  config = Collections.unmodifiableMap(props);
                              }
                              return config;
                          }
                          //Connects to the database
                          public static Connection getDatabaseConnection() throws SQLException, ClassNotFoundException {
                              Map<String, String> dbConfig = getDatabaseConfig();
                              Class.forName(dbConfig.get("database.class"));
                              return DriverManager.getConnection(dbConfig.get("database.url"),
                                      dbConfig.get("database.username"),
                                      dbConfig.get("database.password"));
                          }
                         
                          //Finds the parent apps
                        
                         
                          //Receives the name and finds the employee ID based on it
                          public static Integer getEmployeeIdByName(String name) throws SQLException, ClassNotFoundException {
                              Connection dbConnection = null;
                              ResultSet resultSet = null;
                              PreparedStatement ps = null;

                              try {
                                  dbConnection = getDatabaseConnection();
                                  String query =
                                          "SELECT user_id " +
                                          "FROM CTS_TUser " +
                                          "WHERE first_name + ' '  + last_name = ?";

                                  ps = dbConnection.prepareStatement(query);
                                  ps.setString(1, name);
                                  resultSet = ps.executeQuery();
                                  if (resultSet.next()) {
                                      return resultSet.getInt(1);
                                  }
                              } finally {
                                  if (dbConnection != null) {
                                      dbConnection.close();
                                  }
                                  if (resultSet != null) {
                                      resultSet.close();
                                  }
                                  if (ps != null) {
                                      ps.close();
                                  }
                              }
                              return null;
                          }
                          //Returns a list of all of the employee names
                          public static ArrayList<String> getEmployeeNames() throws SQLException, ClassNotFoundException {
                              Connection dbConnection = null;
                              ResultSet resultSet = null;
                              ArrayList<String> names = new ArrayList<String>();

                              try {
                                  dbConnection = getDatabaseConnection();
                                  String query =
                                          "SELECT first_name + ' ' + last_name " +
                                          "FROM CTS_TUser " +
                                          "ORDER BY last_name";

                                  resultSet = dbConnection.prepareStatement(query).executeQuery();
                                  while (resultSet.next()) {
                                      names.add(resultSet.getString(1));
                                  }
                              } catch (Exception e) {
                                  e.printStackTrace();
                              } finally {
                                  if (dbConnection != null) {
                                      dbConnection.close();
                                  }
                                  if (resultSet != null) {
                                      resultSet.close();
                                  }
                              }
                              return names;
                          }

                          public static ArrayList<String> getBusinessLines() throws SQLException, ClassNotFoundException {
                              Connection dbConnection = null;
                              ResultSet resultSet = null;
                              ArrayList<String> names = new ArrayList<String>();

                              try {
                                  dbConnection = getDatabaseConnection();
                                  String query =
                                          "SELECT * FROM CTS_TBusiness order by 2";

                                  resultSet = dbConnection.prepareStatement(query).executeQuery();
                                  while (resultSet.next()) {
                                      names.add(resultSet.getString(1));
                                  }
                              } catch (Exception e) {
                                  e.printStackTrace();
                              } finally {
                                  if (dbConnection != null) {
                                      dbConnection.close();
                                  }
                                  if (resultSet != null) {
                                      resultSet.close();
                                  }
                              }
                              return names;
                          }
                      }

                      • 8. Re: Code throwing Null exceptoin
                        hphanjra-JavaNet

                        cell renderer does not work properlly class TextAreaEditor1 extends DefaultCellEditor {   protected JScrollPane scrollpane;   protected JTextArea textarea;     public TextAreaEditor1() {       super(new JCheckBox());       scrollpane = new JScrollPane();       textarea = new JTextArea();        textarea.setLineWrap(true);       textarea.setWrapStyleWord(true);       textarea.setBorder(new TitledBorder("This is a JTextArea"));       scrollpane.getViewport().add(textarea);   }     public Component getTableCellEditorComponent(JTable table, Object value,                                   boolean isSelected, int row, int column) {       textarea.setText((String) value);       textarea.append("\nkkkkkkkk");       textarea.append("\n sssssssssskkkkkkkk");       if(!isSelected)textarea.setBackground(Color.cyan);             return scrollpane;   }     public Object getCellEditorValue() {       return textarea.getText();   }

                        • 9. Re: Code throwing Null exceptoin
                          hphanjra-JavaNet

                          package FinCal;

                          /*
                          * TableRenderDemo.java requires no other files.
                          */

                          import javax.swing.BorderFactory;
                          import javax.swing.DefaultCellEditor;
                          import javax.swing.JCheckBox;
                          import javax.swing.JComboBox;
                          import javax.swing.JFrame;
                          import javax.swing.JLabel;
                          import javax.swing.JPanel;
                          import javax.swing.JScrollPane;
                          import javax.swing.JTable;
                          import javax.swing.JTextArea;
                          import javax.swing.border.Border;
                          import javax.swing.border.TitledBorder;
                          import javax.swing.table.AbstractTableModel;
                          import javax.swing.table.DefaultTableCellRenderer;
                          import javax.swing.table.TableCellRenderer;
                          import javax.swing.table.TableColumn;

                          import java.awt.Color;
                          import java.awt.Component;
                          import java.awt.Dimension;
                          import java.awt.GridLayout;
                          import java.awt.Rectangle;
                          import java.awt.event.MouseAdapter;
                          import java.awt.event.MouseEvent;
                          import java.awt.event.MouseListener;

                          /**
                          * TableRenderDemo is just like TableDemo, except that it
                          * explicitly initializes column sizes and it uses a combo box
                          * as an editor for the Sport column.
                          */
                          public class TableRenderDemo extends JPanel {
                              private boolean DEBUG = false;

                              public TableRenderDemo() {
                                  super(new GridLayout(1,0));

                                  JTable table = new JTable(new MyTableModel());
                                  table.setPreferredScrollableViewportSize(new Dimension(700, 270));
                                  table.setFillsViewportHeight(true);

                                  //Create the scroll pane and add the table to it.
                                  JScrollPane scrollPane = new JScrollPane(table);

                                  //Set up column sizes.
                                  initColumnSizes(table);

                                  table.addMouseListener(new MouseAdapter()
                                  {
                                   public void mouseClicked(MouseEvent event) {
                                          System.out.println("Mouse Current selected column ---"+table.getSelectedColumn());    
                                     //     setUp1Column(table,table.getColumnModel().getColumn(0));
                                   }
                                  }
                                  );
                                  //Fiddle with the Sport column's cell editors/renderers.
                                  setUpSportColumn(table, table.getColumnModel().getColumn(2));
                                      setUp1Column(table,table.getColumnModel().getColumn(0));
                                  //Add the scroll pane to this panel.
                                  add(scrollPane);
                              }

                              /*
                               * This method picks good column sizes.
                               * If all column heads are wider than the column's cells'
                               * contents, then you can just use column.sizeWidthToFit().
                               */
                             
                              public void setUp1Column(JTable table,
                                      TableColumn firstname) {
                          System.out.println(" Current selected column ---"+table.getSelectedColumn());
                          table.getColumn("First Name").setCellRenderer(new TextAreaRenderer1());
                          table.getColumn("First Name").setCellEditor(new TextAreaEditor1());

                          table.getColumn("label").setCellRenderer(new Renderer());

                          table.setRowHeight(40);

                          }
                              private void initColumnSizes(JTable table) {
                                  MyTableModel model = (MyTableModel)table.getModel();
                                  TableColumn column = null;
                                  Component comp = null;
                                  int headerWidth = 0;
                                  int cellWidth = 0;
                                  Object[] longValues = model.longValues;
                                  TableCellRenderer headerRenderer =
                                      table.getTableHeader().getDefaultRenderer();

                                  for (int i = 0; i < 5; i++) {
                                      column = table.getColumnModel().getColumn(i);

                                      comp = headerRenderer.getTableCellRendererComponent(
                                                           null, column.getHeaderValue(),
                                                           false, false, 0, 0);
                                      headerWidth = comp.getPreferredSize().width;

                                      comp = table.getDefaultRenderer(model.getColumnClass(i)).
                                                       getTableCellRendererComponent(
                                                           table, longValues[i],
                                                           false, false, 0, i);
                                      cellWidth = comp.getPreferredSize().width;

                                      if (DEBUG) {
                                          System.out.println("Initializing width of column "
                                                             + i + ". "
                                                             + "headerWidth = " + headerWidth
                                                             + "; cellWidth = " + cellWidth);
                                      }

                                      column.setPreferredWidth(Math.max(headerWidth, cellWidth));
                                  }
                              }

                              public void setUpSportColumn(JTable table,
                                                           TableColumn sportColumn) {
                                  //Set up the editor for the sport cells.
                                  JComboBox comboBox = new JComboBox();
                                  comboBox.addItem("Snowboarding");
                                  comboBox.addItem("Rowing");
                                  comboBox.addItem("Knitting");
                                  comboBox.addItem("Speed reading");
                                  comboBox.addItem("Pool");
                                  comboBox.addItem("None of the above");
                                  sportColumn.setCellEditor(new DefaultCellEditor(comboBox));
                                  

                                  //Set up tool tips for the sport cells.
                               DefaultTableCellRenderer renderer =
                                          new DefaultTableCellRenderer();
                               
                                  renderer.setToolTipText("Click for combo box");
                                  System.out.println(" Current selected column ---"+table.getSelectedColumn());
                                
                                  sportColumn.setCellRenderer(renderer);
                           
                              }

                              class MyTableModel extends AbstractTableModel {
                                  private String[] columnNames = {"First Name",
                                                                  "Last Name",
                                                                  "Sport",
                                                                  "# of Years",
                                                                  "Vegetarian",
                                                                  "label"};
                                  private Object[][] data = {
                                  {"Kathy", "Smith",
                                   "Snowboarding", new Integer(5), new Boolean(false), new JLabel("DD")},
                                  /*{"John", "Doe",
                                   "Rowing", new Integer(3), new Boolean(true)},
                                  {"Sue", "Black",
                                   "Knitting", new Integer(2), new Boolean(false)},
                                  {"Jane", "White",
                                   "Speed reading", new Integer(20), new Boolean(true)},
                                 */ {"Joe", "Brown",
                                   "Pool", new Integer(10), new Boolean(false), new JLabel("DD")}        
                                  };

                                  public final Object[] longValues = {"Jane", "Kathy",
                                                                      "None of the above",
                                                                      new Integer(20), Boolean.TRUE,null};

                                  public int getColumnCount() {
                                      return columnNames.length;
                                  }

                                  public int getRowCount() {
                                      return data.length;
                                  }

                                  public String getColumnName(int col) {
                                      return columnNames[col];
                                  }

                                  public Object getValueAt(int row, int col) {
                                      return data[row][col];
                                  }

                                  /*
                                   * JTable uses this method to determine the default renderer/
                                   * editor for each cell.  If we didn't implement this method,
                                   * then the last column would contain text ("true"/"false"),
                                   * rather than a check box.
                                   */
                                  public Class getColumnClass(int c) {
                                      return getValueAt(0, c).getClass();
                                  }

                                  /*
                                   * Don't need to implement this method unless your table's
                                   * editable.
                                   */
                                  public boolean isCellEditable(int row, int col) {
                                      //Note that the data/cell address is constant,
                                      //no matter where the cell appears onscreen.
                                    /*  if (col < 2) {
                                          return false;
                                      } else {
                                          return true;
                                      }
                                      */
                                   return true;
                                  }

                                  /*
                                   * Don't need to implement this method unless your table's
                                   * data can change.
                                   */
                                  public void setValueAt(Object value, int row, int col) {
                                      if (DEBUG) {
                                          System.out.println("Setting value at " + row + "," + col
                                                             + " to " + value
                                                             + " (an instance of "
                                                             + value.getClass() + ")");
                                      }

                                      data[row][col] = value;
                                      fireTableCellUpdated(row, col);

                                      if (DEBUG) {
                                          System.out.println("New value of data:");
                                          printDebugData();
                                      }
                                  }

                                  private void printDebugData() {
                                      int numRows = getRowCount();
                                      int numCols = getColumnCount();

                                      for (int i=0; i < numRows; i++) {
                                          System.out.print("    row " + i + ":");
                                          for (int j=0; j < numCols; j++) {
                                              System.out.print("  " + data[i][j]);
                                          }
                                          System.out.println();
                                      }
                                      System.out.println("--------------------------");
                                  }
                              }

                              /**
                               * Create the GUI and show it.  For thread safety,
                               * this method should be invoked from the
                               * event-dispatching thread.
                               */
                              private static void createAndShowGUI() {
                                  //Create and set up the window.
                                  JFrame frame = new JFrame("TableRenderDemo");
                                  frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

                                  //Create and set up the content pane.
                                  TableRenderDemo newContentPane = new TableRenderDemo();
                                  newContentPane.setOpaque(true); //content panes must be opaque
                                  frame.setContentPane(newContentPane);

                                  //Display the window.
                                  frame.pack();
                                  frame.setVisible(true);
                              }

                              public static void main(String[] args) {
                                  //Schedule a job for the event-dispatching thread:
                                  //creating and showing this application's GUI.
                                  javax.swing.SwingUtilities.invokeLater(new Runnable() {
                                      public void run() {
                                          createAndShowGUI();
                                      }
                                  });
                              }
                          }
                          class Renderer extends DefaultTableCellRenderer {
                             JLabel lbl = new JLabel();

                            //ImageIcon icon = new ImageIcon(getClass().getResource("sample.png"));

                            public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected,
                             boolean hasFocus, int row, int column) {
                          lbl.setText("hello   kjljs");
                            //  lbl.append("\n dddddddddddd");
                          //lbl.setIcon(icon);
                          lbl.setBackground(Color.gray);

                          Border border = BorderFactory.createLineBorder(Color.BLUE, 1);

                           

                           

                          lbl.setBorder(border);;
                          lbl.setBounds(new Rectangle(2,2,12,20));

                          return lbl;

                          }
                          }

                          class TextAreaRenderer1 extends JScrollPane implements TableCellRenderer
                          {
                             JTextArea textarea;
                           
                             public TextAreaRenderer1() {
                                textarea = new JTextArea();
                                textarea.setLineWrap(true);
                                textarea.setWrapStyleWord(true);
                                textarea.setBorder(new TitledBorder("This is a JTextArea"));
                                getViewport().add(textarea);
                             }
                           
                             public Component getTableCellRendererComponent(JTable table, Object value,
                                                            boolean isSelected, boolean hasFocus,
                                                            int row, int column)
                             {
                                if (isSelected) {
                                   setForeground(table.getSelectionForeground());
                                   setBackground(table.getSelectionBackground());
                                   textarea.setForeground(table.getSelectionForeground());
                                   textarea.setBackground(table.getSelectionBackground());
                                } else {
                                   setForeground(table.getForeground());
                                   setBackground(table.getBackground());
                                   textarea.setForeground(table.getForeground());
                                   textarea.setBackground(table.getBackground());
                                }
                           
                                textarea.setText((String) value);
                                textarea.setCaretPosition(0);
                                if(!isSelected)textarea.setBackground(Color.cyan);
                                return this;
                             }
                          }
                           
                          class TextAreaEditor1 extends DefaultCellEditor {
                             protected JScrollPane scrollpane;
                             protected JTextArea textarea;
                           
                             public TextAreaEditor1() {
                                super(new JCheckBox());
                                scrollpane = new JScrollPane();
                                textarea = new JTextArea(); 
                                textarea.setLineWrap(true);
                                textarea.setWrapStyleWord(true);
                                textarea.setBorder(new TitledBorder("This is a JTextArea"));
                                scrollpane.getViewport().add(textarea);
                             }
                           
                             public Component getTableCellEditorComponent(JTable table, Object value,
                                                             boolean isSelected, int row, int column) {
                                textarea.setText((String) value);
                                textarea.append("\nkkkkkkkk");
                                textarea.append("\n sssssssssskkkkkkkk");
                                if(!isSelected)textarea.setBackground(Color.cyan);
                               
                                return scrollpane;
                             }
                           
                             public Object getCellEditorValue() {
                                return textarea.getText();
                             }
                          }