Billing Screen

Billing Page

Above UI, we are going to create by AWT. We will create the Billing Page class.

    

    public class Billingpage {

        public static Dimension screenSize;
        private JButton logoutBtn, addtoCartButton;

        public JFrame dashboardFrame;
        int windowWidth,totalwidth,totalheight,windowHeight,frameControllerSize;
        private Login LoginWindow;
        private JLabel searchtext,totalAvailCount, ShopName,shopAddress,shopGst,TotalAmmount,totalAmmountText,customerNameLabel,customerContactNolabel,date,billNo;
        private JTextField searchTextField,totalAvailCountTextField, customerContactNo, customerNameTextField;
        private JTable table, selectedproductTable;
        private DefaultTableModel defaultdataModel,defaultdataModelForselectedproduct;
        private ArrayList selectedProductList; 		
        private SelectedproductData selectedProductData;
        private String shopNametext,shopAddressText,ShopGsttext;
        
        
        /**
        * Create the Login Window.
        */
        public Billingpage(JFrame LoginFrame, int totalwidth,int totalheight) {
            //screenSize = Toolkit.getDefaultToolkit().getScreenSize();	
            //LoginWindow=new Login(totalwidth, totalheight);
            if(null!=LoginFrame){
                LoginFrame.setVisible(false);

            }
            this.totalheight=totalheight;
            this.totalwidth= totalwidth;
            windowWidth=(totalwidth);
            windowHeight=(totalheight-totalheight/20);
            
            frameControllerSize = (int) (windowHeight * 5.7 / 100);
            selectedProductList=new ArrayList();
            initialize();
        }
    

Before Creating the undefined methods. we have to set up the DATABASE in a seperate class. create a database class naming SQLiteJDBCDriverConnection.java

    

    public class SQLiteJDBCDriverConnection {
    /**
    * Connect to a database
    */

    public static Connection connect1() {
    try {
        // SQLite connection string
        Class.forName("org.sqlite.JDBC");
    } catch (ClassNotFoundException ex) {
        Logger.getLogger(SQLiteJDBCDriverConnection.class.getName()).log(Level.SEVERE, null, ex);
    }
    String url = "jdbc:sqlite:inventry.db";
    Connection conn = null;
    try {
        conn = DriverManager.getConnection(url);
    } catch (SQLException e) {
        System.out.println(e.getMessage());
    }
    return conn;
        }
    }

    

Now, Before initializing all the swing components, lets create Constants in AppConstant class seperately under utilities package.

    

    package utilities;

    public class AppConstant {

        public static String USER_NAME = "Admin";
        public static String USER_PASSWORD = "";
        public static String STAFF_ID = "";


    }

    

Now, Before moving further let us create few customview design classes which we will use while creating the user interface. First we will begin with Background.java under customview package.

    
      
        public class Background extends JComponent {
            
            int width, height,setX,setY;

            public Background (int setX,int setY,int width, int height) {
                this.width=width;
                this.height=height;
                this.setX=setX;
                this.setY=setY;
                
            setSize(width, height);
            }
            
            @Override
            public void paint(Graphics g) {
                Graphics2D g2 = (Graphics2D) g;

                g2.setPaint(Color.white);

                RenderingHints qualityHints = new RenderingHints(
                        RenderingHints.KEY_ANTIALIASING,
                        RenderingHints.VALUE_ANTIALIAS_ON );
                        qualityHints.put(
                        RenderingHints.KEY_RENDERING,
                        RenderingHints.VALUE_RENDER_QUALITY );
                        g2.setRenderingHints( qualityHints );

                //g2.setStroke(new BasicStroke(2.0f));

                double x = setX;
                double y = setY;
                double w = width;
                double h = height;
                RoundRectangle2D round=new RoundRectangle2D.Double(x, y, w, h, 80, 80);
                g2.fill(round);
                
            }

            
        }

    

Create HeaderRender.java in a seperate class under customview package.

    

        /**
        * A simple renderer class for JTable component, but keep the sort icons.
        * @author www.codejava.net
        *
        */
        public class HeaderRender implements TableCellRenderer {
            
            private TableCellRenderer defaultRenderer;
            
            public HeaderRender(TableCellRenderer defaultRenderer) {
                this.defaultRenderer = defaultRenderer;
            }
            


            @Override
            public Component getTableCellRendererComponent(JTable table, Object value,
                    boolean isSelected, boolean hasFocus, int row, int column) {
                Component comp = defaultRenderer.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);

                if (comp instanceof JLabel) {
                    JLabel label = (JLabel) comp;
                    label.setFont(new Font("Consolas", Font.BOLD, 18));
                    label.setForeground(Color.WHITE);
                    label.setBackground(Color.GREEN);
                    label.setBorder(BorderFactory.createEmptyBorder());
                    
                // label.setBorder(BorderFactory.createEtchedBorder());
                    
                }
                
                return comp;
            }
        
        }

    

Create KeepSortIconHeaderRenderer.java in a seperate class under customview package.

    

    /**
    * A simple renderer class for JTable component, but keep the sort icons.
    * @author www.codejava.net
    *
    */
    public class KeepSortIconHeaderRenderer implements TableCellRenderer {
        
        private TableCellRenderer defaultRenderer;
        
        public KeepSortIconHeaderRenderer(TableCellRenderer defaultRenderer) {
            this.defaultRenderer = defaultRenderer;
        }
        


        @Override
        public Component getTableCellRendererComponent(JTable table, Object value,
                boolean isSelected, boolean hasFocus, int row, int column) {
            Component comp = defaultRenderer.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
    
            if (comp instanceof JLabel) {
                JLabel label = (JLabel) comp;
                label.setFont(new Font("Consolas", Font.BOLD, 18));
                label.setForeground(Color.WHITE);
                label.setBackground(Color.GREEN);
                label.setBorder(BorderFactory.createEtchedBorder());
                
            }
            
            return comp;
        }
    
    }


    

Create RoundedBorder.java in a seperate class under customview package.

    

   
    public class RoundedBorder implements Border {

        private int radius;


        RoundedBorder(int radius) {
            this.radius = radius;
        }


        public Insets getBorderInsets(Component c) {
            return new Insets(this.radius+1, this.radius+1, this.radius+2, this.radius);
        }


        public boolean isBorderOpaque() {
            return true;
        }


        public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
            g.drawRoundRect(x, y, width-1, height-1, radius, radius);
        }
    }


    

Now we will initialize all the swing components like JFrame,JTextField, JLabel etc.. in the initialize() method in the BillingPage class.

    

    /**
	 * Initialize the contents of the frame.
	 */
	private void initialize() {

		// frame with control options
		dashboardFrame = new JFrame();
		Utils.centeredFrame(dashboardFrame, windowWidth, windowHeight, "Billig System");
		dashboardFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		//loginFrame.setResizable(false);
		
		Container frameContainer = dashboardFrame.getContentPane();
		frameContainer.setBackground(Color.gray);

		// Changeable According to What size of screen You Want?
		int containerWidth = windowWidth*94/100;
		int containerHeight = windowHeight*90/100;
		
		int panelWidth = containerWidth*98/100;
		int panelHeight = containerHeight*96/100;
		int posX = windowWidth / 2 - panelWidth / 2  -frameControllerSize/5 ;
		int posY = windowHeight / 2 - panelHeight / 2 - frameControllerSize / 2;

		// frame without control options
		JPanel panel = new JPanel(); 
		panel.setLayout(null);//new BorderLayout()); 
		//panel.setOpaque(false);
		panel.setBackground(Color.decode("#FFFFFF")); 
		panel.setSize(new Dimension(panelWidth,panelHeight)); 
		panel.setLocation(posX, posY);
		frameContainer.add(panel);
		
		// for Rounded Background
		posX = windowWidth / 2 - containerWidth / 2 -frameControllerSize/5 ;
		posY = windowHeight / 2 - containerHeight / 2 - frameControllerSize / 2;
		JComponent jcomponent = new Background(posX, posY, containerWidth, containerHeight);
		jcomponent.setLayout(null);
		frameContainer.add(jcomponent, BorderLayout.CENTER);
		

		
		// Your code start from here
		
		// for heading Layout
		posY = panelHeight * 2/100;
		Font headingFont = new Font("Serif", Font.PLAIN, 25);
		// header
		//borderline = BorderFactory.createLineBorder(Color.black);
				
		JLabel heading_text = new JLabel("Billing System");
		heading_text.setHorizontalAlignment(JLabel.CENTER);
		heading_text.setVerticalAlignment(JLabel.CENTER);
		heading_text.setBackground(Color.decode("#80c2b2"));
		heading_text.setForeground(Color.black);
		heading_text.setFont(headingFont);
		heading_text.setBounds(0,0, panelWidth, panelHeight / 9);
		panel.add(heading_text);
		
		headingFont = new Font("Serif", Font.PLAIN, 15);
		JLabel heading_text_minor = new JLabel("Reciept");
		heading_text_minor.setHorizontalAlignment(JLabel.CENTER);
		heading_text_minor.setVerticalAlignment(JLabel.CENTER);
		heading_text_minor.setBackground(Color.decode("#80c2b2"));
		heading_text_minor.setForeground(Color.black);
		heading_text_minor.setFont(headingFont);
		heading_text_minor.setBounds(0,panelHeight*6/100, panelWidth, panelHeight / 9);
		panel.add(heading_text_minor);
				
		panel.add(Utils.getSeparator(0, panelHeight / 7, panelWidth, 5,"000000"));	
        
        
		headingFont = new Font("Serif", Font.PLAIN, 12);
		JLabel admin_text = new JLabel("Hi  "+AppConstant.USER_NAME);
		admin_text.setHorizontalAlignment(JLabel.LEFT);
		admin_text.setVerticalAlignment(JLabel.CENTER);
		admin_text.setBackground(Color.decode("#80c2b2"));
		admin_text.setForeground(Color.black);
		admin_text.setFont(headingFont);
		admin_text.setBounds(panelWidth*2/100,panelHeight/30, panelWidth/2, panelHeight / 10);
		panel.add(admin_text);
		
		panel.add(getLogoutButton(panelWidth, panelHeight));
		

        JPanel leftside =  Utils.createPanel(panelWidth*2/5,panelHeight*6/10,new Point(panelWidth/250,panelHeight/6), true,"Product Window");
        panel.add(leftside,BorderLayout.NORTH);
        leftside.setLayout(null);
        
        JPanel leftdownside =  Utils.createPanel(panelWidth*2/5,panelHeight*23/100,new Point(panelWidth/250,panelHeight/6+panelHeight*6/10), true,"Action");
        panel.add(leftdownside,BorderLayout.EAST);
        leftdownside.setLayout(null);
        
        JPanel rightside =  Utils.createPanel(panelWidth*59/100,panelHeight*83/100,new Point(panelWidth*2/5+panelWidth/100,panelHeight/6), true,"Customer Details");
        panel.add(rightside,BorderLayout.WEST);
        rightside.setLayout(null);
        dashboardFrame.setVisible(true);
        
        Border loweredetched = BorderFactory.createEtchedBorder(EtchedBorder.LOWERED);
        TitledBorder searchTittle = BorderFactory.createTitledBorder(loweredetched, "Search");
        searchTittle.setTitleJustification(TitledBorder.LEFT);
        
        TitledBorder quanatity = BorderFactory.createTitledBorder(loweredetched, "Quantity");
        quanatity.setTitleJustification(TitledBorder.LEFT);
        
        
        TitledBorder customerNameTitel = BorderFactory.createTitledBorder(loweredetched, "Name");
        customerNameTitel.setTitleJustification(TitledBorder.LEFT);
        
        
        TitledBorder customerPhoeneTitel = BorderFactory.createTitledBorder(loweredetched, "Contact No");
        customerPhoeneTitel.setTitleJustification(TitledBorder.LEFT);
        
        searchtext=new JLabel();
        searchtext.setText("Search Available Product");
        searchtext.setForeground(Color.black);
        searchtext.setFont(new Font("Lucida",Font.PLAIN,12));
        searchtext.setSize(new Dimension(panelWidth/3,panelHeight/10));
        searchtext.setLocation(15, 0); 
        leftside.add(searchtext);
        
        

        searchTextField = new JTextField();
        searchTextField.setSize(new Dimension(panelWidth/4,panelHeight/13));
        searchTextField.setLocation(15,panelHeight/13);	
        searchTextField.setBorder(searchTittle);
        leftside.add(searchTextField,BorderLayout.SOUTH);       
        
        searchTextField.getDocument().addDocumentListener(new DocumentListener() {
	         @Override
	         public void insertUpdate(DocumentEvent e) {
	            search(searchTextField.getText());
	            
	         }
	         @Override
	         public void removeUpdate(DocumentEvent e) {
	            search(searchTextField.getText());
	         }
	         @Override
	         public void changedUpdate(DocumentEvent e) {
	            search(searchTextField.getText());
	         }
	         public void search(String str) {
	            if (str.length() == 0) {
	  			  displaylistToTable(panelWidth*38/100,panelHeight/4,table,getTableListData());
	            } else {
	            	defaultdataModel.setRowCount(0);
		  			displaylistToTable(panelWidth*38/100,panelHeight/4,table,getselectedTableListData(str));
	            }
	         }
	      });
        
        
          table = new JTable();			 
		  displaylistToTable(panelWidth*38/100,panelHeight/4,table, getTableListData());
		 
	          JScrollPane pane = new JScrollPane(table);
		      pane.setLocation(15, panelHeight/5-12);
		      pane.setSize(new Dimension(panelWidth*38/100,panelHeight/4));
		      leftside.add(pane);			  
			  table.getSelectionModel().addListSelectionListener(new ListSelectionListener(){
		          public void valueChanged(ListSelectionEvent event) {
		              
		  	        totalAvailCountTextField.setEditable(true);
			        addtoCartButton.setVisible(true);

		              
		          }
		      });

    
		    JTableHeader tableHeader21 = table.getTableHeader();
		    tableHeader21.setDefaultRenderer(new KeepSortIconHeaderRenderer(tableHeader21.getDefaultRenderer()));
        

		    totalAvailCount=new JLabel();
		    totalAvailCount.setText("Total Available in Stock: ");
		    totalAvailCount.setForeground(Color.black);
		    totalAvailCount.setFont(new Font("Lucida",Font.PLAIN,12));
		    totalAvailCount.setSize(new Dimension(panelWidth/3,panelHeight/10));
		    totalAvailCount.setLocation(15, panelHeight/6+panelHeight/4); 
	        leftside.add(totalAvailCount);
	        
	        

	        totalAvailCountTextField = new JTextField();
	        totalAvailCountTextField.setSize(new Dimension(panelWidth/5,panelHeight/13));
	        totalAvailCountTextField.setLocation(15,panelHeight/6+panelHeight/4+panelHeight/12);	
	        totalAvailCountTextField.setBorder(quanatity);
	        leftside.add(totalAvailCountTextField,BorderLayout.SOUTH);       
	        totalAvailCountTextField.setEditable(false);

	        
	        addtoCartButton = new JButton(new ImageIcon(((new ImageIcon("images/button37.png")).getImage()).getScaledInstance(150, 40, java.awt.Image.SCALE_SMOOTH)));
	        addtoCartButton.setContentAreaFilled(false);
	        addtoCartButton.setBorder(null);
	        addtoCartButton.setText("Add to Cart");
	        addtoCartButton.setForeground(Color.white);
	        addtoCartButton.setFont(new Font("Lucida",Font.PLAIN,16));
	        addtoCartButton.setHorizontalTextPosition(JButton.CENTER);
	        addtoCartButton.setVerticalTextPosition(JButton.CENTER);
	        addtoCartButton.setBounds(400,panelHeight/6+panelHeight/4+panelHeight/11,150,40);  
	        addtoCartButton.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
	        addtoCartButton.setVisible(false);
	        leftside.add(addtoCartButton);
	        addtoCartButton.addActionListener(new ActionListener() {
	        	
				@Override
				public void actionPerformed(ActionEvent e) {
					
					
							if(totalAvailCountTextField.getText().toString().isEmpty()){
								JOptionPane.showMessageDialog(frameContainer, "please Enter Quantity");

							}else{
								String Id=table.getValueAt(table.getSelectedRow(), 0).toString();
					        	String productname=table.getValueAt(table.getSelectedRow(), 1).toString();
					        	String productCategory=table.getValueAt(table.getSelectedRow(), 2).toString();
					        	String price=table.getValueAt(table.getSelectedRow(), 3).toString();
				                String count=table.getValueAt(table.getSelectedRow(), 4).toString();
				                String gst=table.getValueAt(table.getSelectedRow(), 5).toString();
				                String EnteredValue=totalAvailCountTextField.getText().toString();				               
				                float total=(Float.parseFloat(price)*Float.parseFloat(EnteredValue))+(Float.parseFloat(price)*Float.parseFloat(EnteredValue))*Float.parseFloat(gst)/100;

								
								selectedProductData=new SelectedproductData(Id,productname,productCategory,
										price,EnteredValue,gst,total);
							    selectedProductList.add(selectedProductData);
						  	    displaylistselectedTable(panelWidth*55/100,panelHeight*44/100,selectedproductTable,selectedProductList);
						  	    addtoCartButton.setVisible(false);
						  	    totalAvailCountTextField.setText("");
						        totalAvailCountTextField.setEditable(false);
								
							}
	
				}
			});
	        
		  
		  
		  
	        JButton generateBill = new JButton(new ImageIcon(((new ImageIcon("images/button37.png")).getImage()).getScaledInstance(150, 40, java.awt.Image.SCALE_SMOOTH)));
	        generateBill.setContentAreaFilled(false);
	        generateBill.setBorder(null);
	        generateBill.setText("Generate Bill");
	        generateBill.setForeground(Color.white);
	        generateBill.setFont(new Font("Lucida",Font.PLAIN,16));
	        generateBill.setHorizontalTextPosition(JButton.CENTER);
	        generateBill.setVerticalTextPosition(JButton.CENTER);
	        generateBill.setBounds(15,(panelHeight*23/100)/2-20,150,40);  
	        generateBill.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
	        leftdownside.add(generateBill);        
	        
	        generateBill.addActionListener(new ActionListener() {
				
				@Override
				public void actionPerformed(ActionEvent e) {
					
					
					
					JPanel myPanel = new JPanel();
				    myPanel.setBounds(0, 0, 500, 450);
				    myPanel.setBackground(Color.WHITE);
					JOptionPane jop = new JOptionPane();
					JDialog dialog = jop.createDialog("Customer Details");
					dialog.setSize(500, 450);					
					dialog.setBackground(Color.WHITE);
				    dialog.setContentPane(myPanel);
				    myPanel.setLayout(null);

				   // dialog.add(jcomponent);
				    
				     JLabel customerName=new JLabel();
					 customerName.setText("Enter The customer Name");
					 customerName.setForeground(Color.black);
					 customerName.setFont(new Font("Lucida",Font.PLAIN,12));
					 customerName.setSize(new Dimension(180,panelHeight/10));
					 customerName.setLocation(60, 25); 
					 myPanel.add(customerName);
					 
				     customerNameTextField = new JTextField();
				     customerNameTextField.setSize(new Dimension(350,panelHeight/13));
				     customerNameTextField.setLocation(60,85);	
				     customerNameTextField.setBorder(customerNameTitel);
				     myPanel.add(customerNameTextField);  
				     
				     
				     JLabel customerContachNo=new JLabel();
				     customerContachNo.setText("Enter Customer Contact No");
				     customerContachNo.setForeground(Color.black);
				     customerContachNo.setFont(new Font("Lucida",Font.PLAIN,12));
				     customerContachNo.setSize(new Dimension(180,panelHeight/10));
				     customerContachNo.setLocation(60, 130);
				     myPanel.add(customerContachNo);  

				     
				     customerContactNo = new JTextField();
				     customerContactNo.setSize(new Dimension(350,panelHeight/13));
				     customerContactNo.setLocation(60,185);	
				     customerContactNo.setBorder(customerPhoeneTitel);
				     myPanel.add(customerContactNo);  
				     
				        JButton submit = new JButton(new ImageIcon(((new ImageIcon("images/button37.png")).getImage()).getScaledInstance(150, 40, java.awt.Image.SCALE_SMOOTH)));
				        submit.setContentAreaFilled(false);
				        submit.setBorder(null);
				        submit.setText("Submit");
				        submit.setForeground(Color.white);
				        submit.setFont(new Font("Lucida",Font.PLAIN,16));
				        submit.setHorizontalTextPosition(JButton.CENTER);
				        submit.setVerticalTextPosition(JButton.CENTER);
				        submit.setBounds(250,280,150,40);  
				        submit.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
				        myPanel.add(submit);   
				        
				        submit.addActionListener(new ActionListener() {
							
							@Override
							public void actionPerformed(ActionEvent e) {
								// TODO Auto-generated method stub
									
								if(customerNameTextField.getText().toString().isEmpty() || customerContactNo.getText().toString().isEmpty()){
									JOptionPane.showMessageDialog(dialog, "Please Enter Customer Name and Contact No");
								}else{
									if(null!=customerContactNolabel && null!= billNo && null!=date && null!= customerNameLabel){
										
										String billNoString=getBillNo();
										int billNoInt=Integer.parseInt(billNoString);
										
										 DecimalFormat df = new DecimalFormat("0000");
					            		 String generatedbillNoString="853"+df.format(billNoInt);
					            		
										long millis=System.currentTimeMillis();  
										java.util.Date datetXT=new java.sql.Date(millis);  
										String dateString=String.valueOf(datetXT);
								        
								        billNo.setText("Bill No : "+generatedbillNoString);
								        date.setText("Date : "+dateString);
								        customerContactNolabel.setText("Contact No : "+customerContactNo.getText().toString());
								        customerNameLabel.setText("Customer Name : "+customerNameTextField.getText().toString());	
								        totalClick();
								        generatePdf("Customer Name : "+customerNameTextField.getText().toString(),"Contact No : "+customerContactNo.getText().toString(),generatedbillNoString,"Date : "+dateString);
								        updateLastCount(Integer.parseInt(billNoString)+1);
								        dialog.dispose();

								        }
								}
																
							}
						});
				        					
					dialog.setVisible(true);
		  					
				}
				
			});
	        
	        
	        
	        JButton totalbutton = new JButton(new ImageIcon(((new ImageIcon("images/button37.png")).getImage()).getScaledInstance(150, 40, java.awt.Image.SCALE_SMOOTH)));
	        totalbutton.setContentAreaFilled(false);
	        totalbutton.setBorder(null);
	        totalbutton.setText("Total");
	        totalbutton.setForeground(Color.white);
	        totalbutton.setFont(new Font("Lucida",Font.PLAIN,16));
	        totalbutton.setHorizontalTextPosition(JButton.CENTER);
	        totalbutton.setVerticalTextPosition(JButton.CENTER);
	        totalbutton.setBounds((panelWidth*2/5)/2-75,(panelHeight*23/100)/2-20,150,40);  
	        totalbutton.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
	        leftdownside.add(totalbutton);
	        totalbutton.addActionListener(new ActionListener() {
				
				@Override
				public void actionPerformed(ActionEvent e) {
					totalClick();
					
				}

				
			});
	        
	        
	        JButton cancleButton = new JButton(new ImageIcon(((new ImageIcon("images/button37.png")).getImage()).getScaledInstance(150, 40, java.awt.Image.SCALE_SMOOTH)));
	        cancleButton.setContentAreaFilled(false);
	        cancleButton.setBorder(null);
	        cancleButton.setText("Clear");
	        cancleButton.setForeground(Color.white);
	        cancleButton.setFont(new Font("Lucida",Font.PLAIN,16));
	        cancleButton.setHorizontalTextPosition(JButton.CENTER);
	        cancleButton.setVerticalTextPosition(JButton.CENTER);
	        cancleButton.setBounds((panelWidth*2/5)-165,(panelHeight*23/100)/2-20 ,150,40);  
	        cancleButton.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
	        leftdownside.add(cancleButton);
	        cancleButton.addActionListener(new ActionListener() {
				
				@Override
				public void actionPerformed(ActionEvent arg0) {
					if (totalAmmountText!=null) {
						totalAmmountText.setVisible(false);
						
					}
					if (TotalAmmount!=null) {
						TotalAmmount.setVisible(false);
						
					}
					if(null!=customerContactNolabel && null!= billNo && null!=date && null!= customerNameLabel){
										        
				        billNo.setText("Bill No : ");
				        date.setText("Date : ");
				        customerContactNolabel.setText("Contact No : ");
				        customerNameLabel.setText("Customer Name : ");	

				      }
					selectedProductList.clear();
					displaylistselectedTable(panelWidth*55/100,panelHeight*44/100,selectedproductTable, selectedProductList);
					
				}
			});
	        
	        
	        shopNametext=getShopNmae();
	        
	        ShopName=new JLabel();
	        ShopName.setText(shopNametext);
	        ShopName.setForeground(Color.black);
	        ShopName.setFont(new Font("Lucida",Font.PLAIN,20));
	        ShopName.setSize(new Dimension(panelWidth*3/5,panelHeight/10));
	        ShopName.setHorizontalAlignment(JLabel.CENTER);
	        ShopName.setLocation(0, 5); 
	        rightside.add(ShopName);
	        
	        
	        
	        shopAddressText=getShopAddress();
	        
	        shopAddress=new JLabel();
	        shopAddress.setText(shopAddressText);
	        shopAddress.setForeground(Color.black);
	        shopAddress.setFont(new Font("Lucida",Font.PLAIN,12));
	        shopAddress.setSize(new Dimension(panelWidth*3/5,panelHeight/10));
	        shopAddress.setHorizontalAlignment(JLabel.CENTER);
	        shopAddress.setLocation(0, 25); 
	        rightside.add(shopAddress);
	        
	        
	        ShopGsttext=getShopGst();

	        shopGst=new JLabel();
	        shopGst.setText("GSTIN :-"+ShopGsttext);
	        shopGst.setForeground(Color.black);
	        shopGst.setFont(new Font("Lucida",Font.PLAIN,15));
	        shopGst.setSize(new Dimension(panelWidth*3/5,panelHeight/10));
	        shopGst.setHorizontalAlignment(JLabel.CENTER);
	        shopGst.setLocation(0, 45); 
	        rightside.add(shopGst);
	        
	
	        
	        customerNameLabel=new JLabel();
	        customerNameLabel.setText("Customer Name : ");
	        customerNameLabel.setForeground(Color.black);
	        customerNameLabel.setFont(new Font("Lucida",Font.PLAIN,15));
	        customerNameLabel.setSize(new Dimension(panelWidth/4,panelHeight/10));
	       // shopGst.setHorizontalAlignment(JLabel.CENTER);
	        customerNameLabel.setLocation(30, 90); 
	        rightside.add(customerNameLabel);
	        
	        
	        
	        customerContactNolabel=new JLabel();
	        customerContactNolabel.setText("Contact No : ");
	        customerContactNolabel.setForeground(Color.black);
	        customerContactNolabel.setFont(new Font("Lucida",Font.PLAIN,15));
	        customerContactNolabel.setSize(new Dimension(panelWidth/6,panelHeight/10));
	       // shopGst.setHorizontalAlignment(JLabel.CENTER);
	        customerContactNolabel.setLocation(panelWidth*2/5, 90); 
	        rightside.add(customerContactNolabel);
	        
	        


	        
	        
	        billNo=new JLabel();
	        billNo.setText("Bill No : ");
	        billNo.setForeground(Color.black);
	        billNo.setFont(new Font("Lucida",Font.PLAIN,15));
	        billNo.setSize(new Dimension(panelWidth/6,panelHeight/10));
	        //shopGst.setHorizontalAlignment(JLabel.CENTER);
	        billNo.setLocation(30, 120); 
	        rightside.add(billNo);
	        
	        date=new JLabel();
	        date.setText("Date : ");
	        date.setForeground(Color.black);
	        date.setFont(new Font("Lucida",Font.PLAIN,15));
	        date.setSize(new Dimension(panelWidth/6,panelHeight/10));
	        //shopGst.setHorizontalAlignment(JLabel.CENTER);
	        date.setLocation(panelWidth*2/5, 120); 
	        rightside.add(date);
	        
	        rightside.add(Utils.getSeparator(30, 180, panelWidth*55/100, 5,"000000"));	
	        
	        
	        
	        selectedproductTable = new JTable();			 
			displaylistselectedTable(panelWidth*55/100,panelHeight*44/100,selectedproductTable, selectedProductList);
			  
            JScrollPane pane2 = new JScrollPane(selectedproductTable);
            pane2.setLocation(30, 200);
            pane2.setBorder(BorderFactory.createEmptyBorder());
            
            pane2.getViewport().setBackground(Color.WHITE);

            pane2.setSize(new Dimension(panelWidth*55/100,panelHeight*44/100));
            rightside.add(pane2);			  
            


    
            JTableHeader tableHeader22 = selectedproductTable.getTableHeader();
            tableHeader22.setDefaultRenderer(new HeaderRender(tableHeader22.getDefaultRenderer()));
            tableHeader22.setPreferredSize(new Dimension(10000, 40));

        
            rightside.add(Utils.getSeparator(30, panelHeight*74/100, panelWidth*55/100, 5,"000000"));	
            rightside.add(Utils.getSeparator(30, panelHeight*81/100, panelWidth*55/100, 5,"000000"));	

            totalAmmountText=new JLabel();
            totalAmmountText.setText("Total Ammount");
            totalAmmountText.setForeground(Color.black);
            totalAmmountText.setFont(new Font("Lucida",Font.PLAIN,15));
            totalAmmountText.setSize(new Dimension(panelWidth/3,panelHeight/10));
            totalAmmountText.setHorizontalAlignment(JLabel.CENTER);
            totalAmmountText.setLocation(0, panelHeight*72/100+5); 
            rightside.add(totalAmmountText);
            totalAmmountText.setVisible(false);

            
            
            TotalAmmount=new JLabel();
            TotalAmmount.setText("12345");
            TotalAmmount.setForeground(Color.black);
            TotalAmmount.setFont(new Font("Lucida",Font.PLAIN,15));
            TotalAmmount.setSize(new Dimension(107,panelHeight/10));
            TotalAmmount.setHorizontalAlignment(JLabel.CENTER);
            TotalAmmount.setLocation(panelWidth/2, panelHeight*72/100+5); 
            TotalAmmount.setVisible(false);
            rightside.add(TotalAmmount);
		        
        panel.revalidate();
        panel.repaint();
        
		
	}


    //// Create the above undefined methods in Utils class seperately under utilities package.

    public class Utils {
        public static JPanel createPanel(int width, int height,Point location,boolean enabled, String titelName) {
                final JPanel panel = new JPanel();
                panel.setOpaque(false);
                panel.setEnabled(enabled);
                panel.setSize(new Dimension(width, height));
                panel.setLocation(location);
                panel.setBorder(BorderFactory.createTitledBorder(titelName));
                panel.setCursor(Cursor.getPredefinedCursor( enabled ? Cursor.CROSSHAIR_CURSOR : Cursor.DEFAULT_CURSOR));
                //System.out.println("cursor: " + Cursor.getPredefinedCursor(enabled ? Cursor.CROSSHAIR_CURSOR : Cursor.DEFAULT_CURSOR));
                return panel;
            }
        
        
            public static void centeredFrame(JFrame frame, int width, int height,String title){
                //frame.setLocationRelativeTo(null);
                
                frame.setSize(width, height); 
                Dimension objDimension = Toolkit.getDefaultToolkit().getScreenSize(); 
                int iCoordX = (objDimension.width - frame.getWidth()) / 2; 
                int iCoordY = (objDimension.height - frame.getHeight()) / 2; 
                frame.setLocation(iCoordX,iCoordY);
                frame.setTitle(title);
                
            }
        
            public static JSeparator getSeparator(int x, int y, int width, int height,String color) {
                JSeparator jSeparator = new JSeparator();
                jSeparator.setBackground(Color.decode("#"+color));
                jSeparator.setAlignmentX(JSeparator.CENTER_ALIGNMENT);
                jSeparator.setBounds(x, y, width, height);
                
                return jSeparator;
            }
    }


    

Create the totalClick() method inside the Billingpage class.

    

	private void totalClick() {
		float totalAmmountadd=0;
		// TODO Auto-generated method stub
		for (int i = 0; i < selectedProductList.size(); i++) {
			totalAmmountadd=totalAmmountadd+selectedProductList.get(i).getTotalPrice();	
		}
		
		if (totalAmmountText!=null) {
			totalAmmountText.setVisible(true);	
		}
		if (TotalAmmount!=null) {
			TotalAmmount.setVisible(true);
			TotalAmmount.setText(String.valueOf(totalAmmountadd));
		}
	}

    

Create the getShopGst() method inside the Billingpage class.

    

	public String getShopGst(){
	 	String shopGst="";
		  ResultSet rs;
    	  String sql = "SELECT value FROM system_info WHERE key = 'SHOP_GST_NO'";
	       Connection conn = SQLiteJDBCDriverConnection.connect1();
	     
	      Statement stat = null;
			try {
				stat = conn.createStatement();
				 rs = stat.executeQuery(sql);
				 shopGst=rs.getString(1);
				stat.close();
				conn.close();	   

			} catch (SQLException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			}
		  return shopGst;
		 
	 }
    

Create the getShopAddress() method inside the Billingpage class.

    

	
	public String getShopAddress(){
	 	String shopAddress="";
		  ResultSet rs;
    	  String sql = "SELECT value FROM system_info WHERE key = 'SHOP_ADDRESS'";
	       Connection conn = SQLiteJDBCDriverConnection.connect1();
	     
	      
	      Statement stat = null;
			try {
				stat = conn.createStatement();
				 rs = stat.executeQuery(sql);
				 shopAddress=rs.getString(1);
				stat.close();
				conn.close();
				   

			} catch (SQLException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			}
      

		  return shopAddress;
		 
	 }

	
    

Create the getShopNmae() method inside the Billingpage class.

    
	
	public String getShopNmae(){
	 	String shopName="";
		  ResultSet rs;
    	  String sql = "SELECT value FROM system_info WHERE key = 'SHOP_NAME'";
	       Connection conn = SQLiteJDBCDriverConnection.connect1();
	     
	      
	      Statement stat = null;
			try {
				stat = conn.createStatement();
				 rs = stat.executeQuery(sql);
				shopName=rs.getString(1);
				stat.close();
				conn.close();
				   

			} catch (SQLException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			}
      

		  return shopName;
		 
	 }
	

	
    

Create the getBillNo() method inside the Billingpage class.

    

	public String getBillNo(){
	 	String shopName="";
		  ResultSet rs;
    	  String sql = "SELECT value FROM system_info WHERE key = 'BILL_LAST_COUNT'";
	       Connection conn = SQLiteJDBCDriverConnection.connect1();
	     
	      
	      Statement stat = null;
			try {
				stat = conn.createStatement();
				 rs = stat.executeQuery(sql);
				shopName=rs.getString(1);
				stat.close();
				conn.close();
				   

			} catch (SQLException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			}
      

		  return shopName;
		 
	 }

	
    

Create the getTableListData() method inside the Billingpage class.

    
	
    public ArrayList getTableListData(){
		 ArrayList productList=new ArrayList();
			 
			  ResultSet rs;
			  String query = "SELECT * FROM product;" ;
		       Connection conn = SQLiteJDBCDriverConnection.connect1();
		     
		      
		      Statement stat = null;
				try {
					stat = conn.createStatement();
					 rs = stat.executeQuery(query);
					 ProductData productData;
					 while(rs.next()){
						 productData=new ProductData(rs.getString("product_id"), rs.getString("product_name"), rs.getString("product_category"), rs.getString("product_price"), rs.getString("product_count"), rs.getString("product_gst"));
						 productList.add(productData);
					 }
					 
					   

				} catch (SQLException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				}
	      

			  return productList;
			 
		 }
	 

	
    

Create the displaylistselectedTable() method inside the Billingpage class.

    

    public void displaylistselectedTable(int panelWidth,int paneHeight,JTable table, ArrayList productList){	 
        
        defaultdataModelForselectedproduct=new DefaultTableModel();
        Object []row=new Object[7];

        defaultdataModelForselectedproduct.setColumnIdentifiers(new Object[]{"ID","Name","Category","Price","Count","Gst","Total"});


        for (int i = 0; i < productList.size(); i++) {

            row[0]=productList.get(i).getId();
            row[1]=productList.get(i).getProductName();
            row[2]=productList.get(i).getProductCategory();
            row[3]=productList.get(i).getProductPrice();
            row[4]=productList.get(i).getProductCount();
            row[5]=productList.get(i).getProductGst();
            row[6]=productList.get(i).getTotalPrice();

            defaultdataModelForselectedproduct.addRow(row);


        }
        defaultdataModelForselectedproduct.isCellEditable(0, 0);
            

        table.setModel(defaultdataModelForselectedproduct);
        DefaultTableCellRenderer centerRenderer = new DefaultTableCellRenderer();
        centerRenderer.setHorizontalAlignment( JLabel.CENTER );
        table.getColumnModel().getColumn(0).setCellRenderer( centerRenderer );
        table.getColumnModel().getColumn(1).setCellRenderer( centerRenderer );
        table.getColumnModel().getColumn(2).setCellRenderer( centerRenderer );
        table.getColumnModel().getColumn(3).setCellRenderer( centerRenderer );
        table.getColumnModel().getColumn(4).setCellRenderer( centerRenderer );
        table.getColumnModel().getColumn(5).setCellRenderer( centerRenderer );
        table.getColumnModel().getColumn(6).setCellRenderer( centerRenderer );

        table.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
        table.getColumnModel().getColumn(1).setPreferredWidth(200);

        table.setRowHeight(30);
        table.setShowHorizontalLines(false);
        table.setShowVerticalLines(false);
        //	        JTableHeader tableHeader =  new JTableHeader();
        //
        //	        table.setTableHeader(tableHeader);
        //
        //	        tableHeader.setDefaultRenderer(centerRenderer);

}
    

Create the displaylistToTable() method inside the Billingpage class.

    

    
	 public void displaylistToTable(int panelwidth,int panelHeight,JTable table,ArrayList productList){
		 
		 defaultdataModel=new DefaultTableModel();
		 Object []row=new Object[6];

		 defaultdataModel.setColumnIdentifiers(new Object[]{"ID","Name","Category","Price","Count","Gst"});
		 
		 for (int i = 0; i < productList.size(); i++) {

			 row[0]=productList.get(i).getId();
			 row[1]=productList.get(i).getProductName();
			 row[2]=productList.get(i).getProductCategory();
			 row[3]=productList.get(i).getProductPrice();
			 row[4]=productList.get(i).getProductCount();
			 row[5]=productList.get(i).getProductGst();

			 defaultdataModel.addRow(row);


		}
		 defaultdataModel.isCellEditable(0, 0);
		 
		
		 table.setModel(defaultdataModel);
		 DefaultTableCellRenderer centerRenderer = new DefaultTableCellRenderer();
	      centerRenderer.setHorizontalAlignment( JLabel.CENTER );
		  table.getColumnModel().getColumn(0).setCellRenderer( centerRenderer );
		  table.getColumnModel().getColumn(1).setCellRenderer( centerRenderer );
		  table.getColumnModel().getColumn(2).setCellRenderer( centerRenderer );
		  table.getColumnModel().getColumn(3).setCellRenderer( centerRenderer );
		  table.getColumnModel().getColumn(4).setCellRenderer( centerRenderer );
		  table.getColumnModel().getColumn(5).setCellRenderer( centerRenderer );
		  table.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
	      table.getColumnModel().getColumn(1).setPreferredWidth(panelwidth/5);
	      table.getColumnModel().getColumn(2).setPreferredWidth(panelwidth/6);

	        table.setRowHeight(30);


		 
	 }
	  
    

Create the getselectedTableListData() method inside the Billingpage class.

    

	 
    public ArrayList getselectedTableListData(String data){
	 ArrayList productList=new ArrayList();
		 
		  ResultSet rs;
		 String query = "SELECT * FROM product WHERE product_id LIKE '%" + data + "%' or product_name LIKE '%" + data + "%' " ;
	      Connection conn = SQLiteJDBCDriverConnection.connect1();
	      Statement stat = null;
			try {
				stat = conn.createStatement();
				 rs = stat.executeQuery(query);
				 ProductData productData;
				 while(rs.next()){
					 productData=new ProductData(rs.getString("product_id"), rs.getString("product_name"), rs.getString("product_category"), rs.getString("product_price"), rs.getString("product_count"), rs.getString("product_gst"));
					 productList.add(productData);
					 
				 }
				 
				   rs.close();
				   stat.close();
			       conn.close();  
			} catch (SQLException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			}
	  
		      
		  return productList;
		 
	 } 

	 
	  
    

Create the updateLastCount() method inside the Billingpage class.

    
    public void updateLastCount(int lastCount) {
			 
		 	Connection	conn=SQLiteJDBCDriverConnection.connect1();
	         boolean issuccess=false;
	         Statement stmt = null;
	         int action;		            
	         String newValue = String.valueOf(lastCount);
	         String  idToMatch = "BILL_LAST_COUNT";
	         
	        
	         String sqlUpdate = "UPDATE system_info "
	                 + "SET value = ? "
	                 + "WHERE key = ?";
		      
	 
		        PreparedStatement pst  = null;
		        ResultSet rs = null;
		        try {
	             pst = conn.prepareStatement(sqlUpdate);
	
		        	pst.setString(1, newValue);
		        	pst.setString(2, idToMatch);
		        	
		        	pst.executeUpdate();
			            action = pst.executeUpdate();
			            if(action>0){
					    	   issuccess= true;
			 
					       }else{
					    	   issuccess= false;
	
					       }
			           
		            } catch (Exception a) {
		                a.printStackTrace();
		            } finally {
		                if(rs != null){
		                     try{
		                          rs.close();
		                     } catch(Exception e){
		                         e.printStackTrace();
		                     }
		                }
		                if(pst != null){
		                    try{
		                        pst.close();
		                    } catch(Exception e){
		                        e.printStackTrace();
		                    }
		                }
		            }
    
	}
	
    

Create the generatePdf() method inside the Billingpage class.

    

    public void generatePdf(String customerName,String customerContactNo,String billNo,String date){
        
        Document document = new Document();
        try
        {
            PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("pdf/"+billNo+".pdf"));
            document.open();

            com.itextpdf.text.Font titleFont = FontFactory.getFont(FontFactory.HELVETICA_BOLD,20f);

            Paragraph shopName = new Paragraph(shopNametext,titleFont); 
            shopName.setAlignment(Element.ALIGN_CENTER);
            
            document.add(shopName);
            titleFont = FontFactory.getFont(FontFactory.HELVETICA_BOLD,7f);
            Paragraph shopaddress = new Paragraph(shopAddressText,titleFont); 
            shopaddress.setAlignment(Element.ALIGN_CENTER);
            document.add(shopaddress);

            titleFont = FontFactory.getFont(FontFactory.HELVETICA_BOLD,10f);
            Paragraph shopgst = new Paragraph("GSTIN: -"+ShopGsttext,titleFont); 
            shopgst.setAlignment(Element.ALIGN_CENTER);
            document.add(shopgst);
            
        
            
            titleFont = FontFactory.getFont(FontFactory.HELVETICA,12f);

            PdfPTable table = new PdfPTable(2); // 3 columns.
            table.setWidthPercentage(100); //Width 100%
            table.setSpacingBefore(10f); //Space before table
            table.setSpacingAfter(10f); //Space after table

            //Set Column widths
            float[] columnWidths = {1f, 1f};
            table.setWidths(columnWidths);

            PdfPCell cell1 = new PdfPCell(new Paragraph(customerName,titleFont));
            cell1.setBorderColor(BaseColor.WHITE);
            cell1.setPaddingLeft(10);
            cell1.setHorizontalAlignment(Element.ALIGN_LEFT);
            cell1.setVerticalAlignment(Element.ALIGN_MIDDLE);

    
            PdfPCell cell3 = new PdfPCell(new Paragraph("                "+customerContactNo,titleFont));
            cell3.setBorderColor(BaseColor.WHITE);
            cell3.setPaddingLeft(10);
            cell3.setHorizontalAlignment(Element.ALIGN_LEFT);
            cell3.setVerticalAlignment(Element.ALIGN_MIDDLE);
            
            

            PdfPCell cell4 = new PdfPCell(new Paragraph("Bill No : "+billNo,titleFont));
            cell4.setBorderColor(BaseColor.WHITE);
            cell4.setPaddingLeft(10);
            cell4.setHorizontalAlignment(Element.ALIGN_LEFT);
            cell4.setVerticalAlignment(Element.ALIGN_MIDDLE);

    
            PdfPCell cell5 = new PdfPCell(new Paragraph("                "+date,titleFont));
            cell5.setBorderColor(BaseColor.WHITE);
            cell5.setPaddingLeft(10);
            cell5.setHorizontalAlignment(Element.ALIGN_LEFT);
            cell5.setVerticalAlignment(Element.ALIGN_MIDDLE);

            //To avoid having the cell border and the content overlap, if you are having thick cell borders
            //cell1.setUserBorderPadding(true);
            //cell2.setUserBorderPadding(true);
            //cell3.setUserBorderPadding(true);

            table.addCell(cell1);

            table.addCell(cell3);
            table.addCell(cell4);

            table.addCell(cell5);

            document.add(table);
            
            
            LineSeparator dottedline = new LineSeparator();
            dottedline.setOffset(-2);
            document.add(dottedline);
            
            
            int columnWIdth[]={70,300,100,100,100,100};
            PdfPTable productHeadingTable = new PdfPTable(6);
            productHeadingTable.setWidths(columnWIdth);
            productHeadingTable.setSpacingBefore(3f); //Space before table
            productHeadingTable.setSpacingAfter(3f); 
            
            
            PdfPCell c1= new PdfPCell(new Phrase("S.no"));
            c1.setHorizontalAlignment(Element.ALIGN_CENTER);
            c1.setVerticalAlignment(Element.ALIGN_MIDDLE);
            c1.setBorderColor(BaseColor.WHITE);
            productHeadingTable.addCell(c1);


            PdfPCell c2 = new PdfPCell(new Phrase("Name"));
            c2.setHorizontalAlignment(Element.ALIGN_CENTER);
            c2.setVerticalAlignment(Element.ALIGN_MIDDLE);
            c2.setBorderColor(BaseColor.WHITE);
            productHeadingTable.addCell(c2);

            PdfPCell c3 = new PdfPCell(new Phrase("Gst"));
            c3.setHorizontalAlignment(Element.ALIGN_CENTER);
            c3.setVerticalAlignment(Element.ALIGN_MIDDLE);
            c3.setBorderColor(BaseColor.WHITE);
            productHeadingTable.addCell(c3);

            PdfPCell	c4 = new PdfPCell(new Phrase("Price"));
            c4.setHorizontalAlignment(Element.ALIGN_CENTER);
            c4.setVerticalAlignment(Element.ALIGN_MIDDLE);
            c4.setBorderColor(BaseColor.WHITE);
            productHeadingTable.addCell(c4);

            
            PdfPCell c5 = new PdfPCell(new Phrase("Quantity"));
            c5.setHorizontalAlignment(Element.ALIGN_CENTER);
            c5.setVerticalAlignment(Element.ALIGN_MIDDLE);
            c5.setFixedHeight(30);
            c5.setBorderColor(BaseColor.WHITE);
            productHeadingTable.addCell(c5);

            PdfPCell c6 = new PdfPCell(new Phrase("Total"));
            c6.setHorizontalAlignment(Element.ALIGN_CENTER);
            c6.setVerticalAlignment(Element.ALIGN_MIDDLE);
            c6.setBorderColor(BaseColor.WHITE);
            productHeadingTable.addCell(c6);

            document.add(productHeadingTable);

            dottedline = new LineSeparator();
            dottedline.setOffset(-2);
            document.add(dottedline);
                
            
            
            PdfPTable productTable = new PdfPTable(6);
            productTable.setWidths(columnWIdth);
            productTable.setSpacingBefore(10);
            productTable.setSpacingAfter(10f); 


            for(int i=0;i< selectedProductList.size();i++){
                
                    String temp = String.valueOf(i+1);
                    String temp1 = selectedProductList.get(i).getProductName();
                    String temp2 =String.valueOf(selectedProductList.get(i).getProductGst());
                    String temp3 =String.valueOf(selectedProductList.get(i).getProductPrice());
                    String temp4 =String.valueOf(selectedProductList.get(i).getProductCount());
                    String temp5 =String.valueOf(selectedProductList.get(i).getTotalPrice());


                    if(temp1.equalsIgnoreCase("")){
                        temp1="*"; // this fills the cell with * if the String is empty otherwise cell won't be created
                    }

                    if(temp2.equalsIgnoreCase("")){
                        temp2="*"; // this fills the cell with * if the String is empty otherwise cell won't be created
                        }
    
                    productTable.addCell(getPdfCell(temp)  ); // rows for first column
                    productTable.addCell(getPdfCell(temp1)  );
                    productTable.addCell( getPdfCell(temp2)    ); // rows for first column
                    productTable.addCell(getPdfCell(temp3)  );
                    productTable.addCell( getPdfCell(temp4)    ); // rows for first column
                    productTable.addCell(getPdfCell(temp5)  );

            }
            document.add(productTable);
            dottedline = new LineSeparator();
            dottedline.setOffset(-2);
            document.add(dottedline);
            float totalAmmountadd=0;
            // TODO Auto-generated method stub
            for (int i = 0; i < selectedProductList.size(); i++) {
                totalAmmountadd=totalAmmountadd+selectedProductList.get(i).getTotalPrice();
                
                
            }
            Paragraph TotalOverallPrice = new Paragraph("Rounded Total (in Rs) : "+totalAmmountadd+"                  "); 
            TotalOverallPrice.setAlignment(Element.ALIGN_RIGHT);	
            TotalOverallPrice.setSpacingBefore(7);
                TotalOverallPrice.setSpacingAfter(12);
                document.add(TotalOverallPrice);
                
            

                dottedline = new LineSeparator();
                dottedline.setOffset(-1);
                document.add(dottedline);

                Paragraph Sign = new Paragraph("Sign Of Shopkeeper"); 
                Sign.setAlignment(Element.ALIGN_RIGHT);		           
                document.add(Sign);
                Sign.setSpacingBefore(15);

            

            document.close();
            writer.close();
        } catch (DocumentException e1)
        {
            e1.printStackTrace();
        } catch (FileNotFoundException e1)
        {
            e1.printStackTrace();
        }
    }
    

Create the getPdfCell() method inside the Billingpage class.

    

    public static PdfPCell getPdfCell(String temp) {

        PdfPCell c6 = new PdfPCell(new Phrase(temp));
        c6.setHorizontalAlignment(Element.ALIGN_CENTER);
        c6.setVerticalAlignment(Element.ALIGN_MIDDLE);
        c6.setBorderColor(BaseColor.WHITE);
        return c6;
    }
    

Create the getLogoutButton() method inside the Billingpage class.

    

    private JButton getLogoutButton(int width, int height) {
			  
              logoutBtn = new JButton(new ImageIcon(((new ImageIcon("images/button37.png")).getImage()).getScaledInstance( width*12/100, height*5/100, java.awt.Image.SCALE_SMOOTH)));
              logoutBtn.setContentAreaFilled(false);
              logoutBtn.setBorder(null);
              logoutBtn.setText("LOGOUT");
              logoutBtn.setHorizontalTextPosition(JButton.CENTER);
              logoutBtn.setVerticalTextPosition(JButton.CENTER);
              logoutBtn.setBounds(width*83/100,(int) (height/23), width*12/100, height*5/100); 
              logoutBtn.setFont(new java.awt.Font("Serif",0, 10));
              logoutBtn.setForeground(Color.white);
              
              logoutBtn.addActionListener(new ActionListener() {
                  
                  @Override
                  public void actionPerformed(ActionEvent e) {
                      // TODO Auto-generated method stub
                      
                      moveToLogin();
                      
      
                  }
              });
              
              return logoutBtn;		
          }
      
    

Create the moveToLogin() method inside the Billingpage class.

    

		private void moveToLogin() {
			 dashboardFrame.dispose();
			 LoginWindow=new Login(totalwidth, totalheight);
			 LoginWindow.getFrameRef().setVisible(true);
		 	 updateisLoginValue("0");
			}

    

Create the updateisLoginValue() method inside the Billingpage class.

    

    public void updateisLoginValue(String updatValue) {
				 
                 Connection conn=SQLiteJDBCDriverConnection.connect1();
                boolean issuccess=false;
                Statement stmt = null;
                int action;		            
                String newValue = updatValue;
                String  idToMatch = "IS_LOGINED";
                
               
                String sqlUpdate = "UPDATE system_info "
                        + "SET value = ? "
                        + "WHERE key = ?";
                 
        
                   PreparedStatement pst  = null;
                   ResultSet rs = null;
                   try {
                    pst = conn.prepareStatement(sqlUpdate);
   
                       pst.setString(1, newValue);
                       pst.setString(2, idToMatch);
                       
                       pst.executeUpdate();
                           action = pst.executeUpdate();
                           if(action>0){
                                  issuccess= true;
                
                              }else{
                                  issuccess= false;
   
                              }
                          
                       } catch (Exception a) {
                           a.printStackTrace();
                       } finally {
                           if(rs != null){
                                try{
                                     rs.close();
                                } catch(Exception e){
                                    e.printStackTrace();
                                }
                           }
                           if(pst != null){
                               try{
                                   pst.close();
                               } catch(Exception e){
                                   e.printStackTrace();
                               }
                           }
                       }
                     
       }
  
    

Programmer Mirta is for learning and training. Projects might be simple to improve learning. Projects are constantly reviewed to avoid errors, but we cannot assure full correctness of all content. While using Programmer Mitra, you agree to have read and accepted our terms of use, cookie and privacy policy.

Copyright 2021 by Programmer Mitra. All Rights Reserved.