Add/Edit Customer

Add Customer

Above UI we are going to create by Java for adding customer in our Bank management system desktop application. For that first we create a window and configure its title, size and color. Here we are creating a window at Top Level so we can add this window at the top of any other window.

    
      
        this.dashboardFrame = jframe;
		dashboardFrame.setVisible(false);
		screenSize = Toolkit.getDefaultToolkit().getScreenSize();

		windowWidth = (int) (screenSize.getWidth() *90 /100);
		windowHeight = (int) (windowWidth * 56 / 100);
		frameControllerSize = (int) (windowHeight * 5.7 / 100);


        addCustomerFrame = new JFrame();
		Utils.centeredFrame(addCustomerFrame, windowWidth, windowHeight, "Add/Edit Customer");
		addCustomerFrame.setResizable(false);
		
		Container frameContainer = addCustomerFrame.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 ;
		int posY = windowHeight / 2 - panelHeight / 2 - frameControllerSize / 2;

		// frame without control options
		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 ;
		posY = windowHeight / 2 - containerHeight / 2 - frameControllerSize / 2;
		JComponent jcomponent = new RoundedBackground(posX, posY, containerWidth, containerHeight);
		jcomponent.setLayout(null);
		frameContainer.add(jcomponent, BorderLayout.CENTER);
		

     	
    

Here is our class RoundedBackground:

    
    
    public class RoundedBackground extends JComponent {
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	int width, height,setX,setY;

    public RoundedBackground (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.setRenderingHint(
                RenderingHints.KEY_ANTIALIASING,
                RenderingHints.VALUE_ANTIALIAS_ON);
        g2.setPaint(Color.white);

        //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);

    }

    
}


    

Here we create Labels and Text Fields.

    
   
        posY = panelHeight * 2/100;
		Font headingFont = new Font("Serif", Font.PLAIN, 22);
		// header
		Border borderline = BorderFactory.createLineBorder(Color.black);
				
		JLabel heading_text = new JLabel("Add/Edit Customer");
		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 / 15);
		panel.add(heading_text);
				
		panel.add(Utils.getSeparator(0, panelHeight / 13, panelWidth, 5,"000000"));			

	
		
		
	
	    // passenger table Base panel
		
	    
	    // Action table Base panel
	
		actionPanelWidth = panelWidth*35/100;
		actionPanelHeight = panelHeight*86/100;
	    actionPanel = new JPanel();
	    actionPanel.setBorder(Utils.getTitledBorder(10, "Action"));
	    //controlPanel.add(new MyCanvas());
	    actionPanel.setBounds(0,panelHeight*10/100, actionPanelWidth, actionPanelHeight);
	    actionPanel.setLayout(null);
	    actionPanel.setName("Action");
	    panel.add(actionPanel);
	    
	    
	    Font textFont = new Font("Serif",0,12);
	    JLabel customerNameL = new JLabel("Customer Name");
	    customerNameL.setAlignmentX(customerNameL.LEFT_ALIGNMENT);
	    customerNameL.setAlignmentY(customerNameL.LEFT_ALIGNMENT);
	    customerNameL.setForeground(Color.black);
	    customerNameL.setFont(textFont);
	    customerNameL.setBounds(actionPanelWidth*10/100,actionPanelHeight*10/100, 300, 20);
	    customerNameL.setBackground(Color.black);
	    actionPanel.add(customerNameL);
	    
	    customerNameField = new JTextField();
	    customerNameField.setForeground(Color.black);
	    customerNameField.setBounds(actionPanelWidth*10/100,actionPanelHeight*15/100, 300, 30);
	    customerNameField.setOpaque(false);
	    customerNameField.setBorder(BorderFactory.createLineBorder(Color.white, 0));
	    customerNameField.setBackground(null);
	    actionPanel.add(customerNameField);
	    
	    actionPanel.add(Utils.getSeparator(actionPanelWidth*10/100,actionPanelHeight*20/100,actionPanelWidth*80/100,5,"000000"));
	    
	    JLabel contactL = new JLabel("Contact No");
	    contactL.setAlignmentX(contactL.LEFT_ALIGNMENT);
	    contactL.setAlignmentY(contactL.LEFT_ALIGNMENT);
	    contactL.setForeground(Color.black);
	    contactL.setFont(textFont);
	    contactL.setBounds(actionPanelWidth*10/100,actionPanelHeight*25/100, 300, 20);
	    contactL.setBackground(Color.black);
	    actionPanel.add(contactL);
	    
	    contactField = new JTextField();
	    contactField.setForeground(Color.black);
	    contactField.setBounds(actionPanelWidth*10/100,actionPanelHeight*30/100, 300, 30);
	    contactField.setOpaque(false);
	    contactField.setBorder(BorderFactory.createLineBorder(Color.white, 0));
	    contactField.setBackground(null);
	    actionPanel.add(contactField);
	    
	    actionPanel.add(Utils.getSeparator(actionPanelWidth*10/100,actionPanelHeight*35/100,actionPanelWidth*80/100,5,"000000"));

	    
	    JLabel emailL = new JLabel("Email Id");
	    emailL.setAlignmentX(emailL.LEFT_ALIGNMENT);
	    emailL.setAlignmentY(emailL.LEFT_ALIGNMENT);
	    emailL.setForeground(Color.black);
	    emailL.setFont(textFont);
	    emailL.setBounds(actionPanelWidth*10/100,actionPanelHeight*40/100, 300, 20);
	    emailL.setBackground(Color.black);
	    actionPanel.add(emailL);
	    
	    emailField = new JTextField();
	    emailField.setForeground(Color.black);
	    emailField.setBounds(actionPanelWidth*10/100,actionPanelHeight*45/100, 300, 30);
	    emailField.setOpaque(false);
	    emailField.setBorder(BorderFactory.createLineBorder(Color.white, 0));
	    emailField.setBackground(null);
	    actionPanel.add(emailField);
	    
	    actionPanel.add(Utils.getSeparator(actionPanelWidth*10/100,actionPanelHeight*50/100,actionPanelWidth*80/100,5,"000000"));
	    
   
	    JLabel addsL = new JLabel("Address");
	    addsL.setAlignmentX(addsL.LEFT_ALIGNMENT);
	    addsL.setAlignmentY(addsL.LEFT_ALIGNMENT);
	    addsL.setForeground(Color.black);
	    addsL.setFont(textFont);
	    addsL.setBounds(actionPanelWidth*10/100,actionPanelHeight*55/100, 300, 20);
	    addsL.setBackground(Color.black);
	    actionPanel.add(addsL);
	    
	    addsField = new JTextField();
	    addsField.setForeground(Color.black);
	    addsField.setBounds(actionPanelWidth*10/100,actionPanelHeight*60/100, 300, 30);
	    addsField.setOpaque(false);
	    addsField.setBorder(BorderFactory.createLineBorder(Color.white, 0));
	    addsField.setBackground(null);
	    actionPanel.add(addsField);
	    
	    actionPanel.add(Utils.getSeparator(actionPanelWidth*10/100,actionPanelHeight*65/100,actionPanelWidth*80/100,5,"000000"));

    

Here we Define Utils class separator method.

    
   
    public static JSeparator getSeparator(int x, int y, int width, int height,String color) {
		 	JSeparator jSeparator = new JSeparator();
			jSeparator.setBackground(Color.decode("#"+color));
			jSeparator.setBorder(null);
			jSeparator.setOpaque(false);
			jSeparator.setAlignmentX(JSeparator.CENTER_ALIGNMENT);
	        jSeparator.setBounds(x, y, width, height);
	        
		    return jSeparator;
		}


  
        
    

Here we Define "ADD CUSTOMER" Button and its click.

    
   
	    addCustomerBtn = new JButton(new ImageIcon(((new ImageIcon("images/button32.png")).getImage()).getScaledInstance(250, 50, java.awt.Image.SCALE_SMOOTH)));
		addCustomerBtn.setContentAreaFilled(false);
		addCustomerBtn.setBorder(null);
		addCustomerBtn.setText("ADD CUSTOMER");
		addCustomerBtn.setHorizontalTextPosition(JButton.CENTER);
		addCustomerBtn.setVerticalTextPosition(JButton.CENTER);
		addCustomerBtn.setBounds(actionPanelWidth/2-125,actionPanelHeight*85/100, 250, 50); 
		addCustomerBtn.setOpaque(false);
		addCustomerBtn.setContentAreaFilled(false);
		addCustomerBtn.setBorderPainted(false);
		addCustomerBtn.setFont(new java.awt.Font("Serif",1, 15));
		addCustomerBtn.setForeground(Color.white);
		actionPanel.add(addCustomerBtn);
	    
		
		addCustomerBtn.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent e) {
				
				String var = "";
				boolean is_name_entered = false;
				boolean is_contact_entered = false;
				boolean is_email_entered = false;
				boolean is_adds_entered = false;
				
				String stfId = "CTM";
				String name = customerNameField.getText();
				String contact = contactField.getText();
				String email = emailField.getText();
				
				String credit = "";
				String debit = "";
				int balance = 0;
				String credit_date = "";
				String debit_date = "";
				
				String adds = addsField.getText();
				
				int acc_no = Utils.generateRandomDigits(8);
//				int trans_id = Utils.generateRandomDigits(12);
				long trans_id = Utils.generateRandom(12);

				int id_count = 0;
				String key = "CUSTOMER_LAST_COUNT";
				
				if(name.isEmpty()) {
					var += "Name Should not be empty, ";
		        }else {
		        	is_name_entered = true;
		        }
				
				if(contact.isEmpty()) {
					var += "Contact Should not be empty, ";
		        }else {
		        	is_contact_entered = true;
		        }
				
				if(email.isEmpty()) {
					var += "Email id Should not be empty, ";
		        }else {
		        	is_email_entered = true;
		        }
				
				
				
				if(adds.isEmpty()) {
					var += "Address Should not be empty, ";
		        }else {
		        	is_adds_entered = true;
		        }
				
				
				
				if(is_name_entered && is_contact_entered && is_email_entered && is_adds_entered) {
				conn = SQLiteJDBCDriverConnection.connect1();
				
				try {
					
					insert = conn.prepareStatement("SELECT value FROM system_setting WHERE key = 'CUSTOMER_LAST_COUNT'");
					ResultSet rs = insert.executeQuery();
					ResultSetMetaData rsmd = rs.getMetaData();
					 
					 while (rs.next()) {    
						 id_count = rs.getInt(1)+1;  
				        }
					 DecimalFormat df = new DecimalFormat("000");
					 stfId = stfId+df.format(id_count);
				} catch (SQLException e2) {
					// TODO Auto-generated catch block
					e2.printStackTrace();
				}
				
				
				
				try {
					insert = conn.prepareStatement("insert into customer(customer_id,customer_name,contact_number,email_address,address,account_number,status)values(?,?,?,?,?,?,?)");
					insert.setString(1, stfId);
					insert.setString(2, name);
					insert.setString(3, contact);
					insert.setString(4, email);
					insert.setString(5, adds);
					insert.setInt(6, acc_no);
					insert.setString(7, "Active");
					insert.executeUpdate();
				} catch (SQLException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				}
				
				
				try {
					insert = conn.prepareStatement("insert into statement(transaction_id,account_number,credit,debit, balance, credit_date, debit_date)values(?,?,?,?,?,?,?)");
					insert.setLong(1, trans_id);
					insert.setInt(2, acc_no);
					insert.setString(3, credit);
					insert.setString(4, debit);
					insert.setInt(5, balance);
					insert.setString(6, credit_date);
					insert.setString(7, debit_date);
					insert.executeUpdate();
				} catch (SQLException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				}
				
				
				
				
				try {
					
					insert = conn.prepareStatement("UPDATE system_setting "
			                + "SET value = ? "
			                + "WHERE key = ?");
					insert.setInt(1, id_count);
					insert.setString(2, key);
					insert.executeUpdate();
					conn.close();
				} catch (SQLException e3) {
					// TODO Auto-generated catch block
					e3.printStackTrace();
				}
				
				customer_table_update();
				customerNameField.setText("");
	            contactField.setText("");
	            emailField.setText("");
	            addsField.setText("");
	            
	            var = "Customer has been added successfully";
				JOptionPane.showMessageDialog(null, var);
	            
			}else {
				JOptionPane.showMessageDialog(null, var);
			}
					
			}
		});



  
        
    

Now Create a Search UI for already added Customer in customer table. First we create a entry box to search Customer with Customer Name and Account Number.

    
        
        int staffPanelWidth = panelWidth*64/100;
		int staffPanelHeight = panelHeight*86/100;
	    customerPanel = new JPanel();
	    customerPanel.setLayout(new FlowLayout());
	    customerPanel.setLayout(null);
	    customerPanel.setBounds(panelWidth*36/100,panelHeight*10/100, staffPanelWidth, staffPanelHeight);
	    customerPanel.setBorder(Utils.getTitledBorder(10, "Search"));
	    panel.add(customerPanel);
	    
	    headingFont = new Font("Serif",Font.BOLD,18);
	    JLabel customer_search_L = new JLabel("Search Customer");
	    customer_search_L.setAlignmentX(JLabel.LEFT);
	    //searchLabel.setBackground(Color.decode("#80c2b2"));
	    customer_search_L.setForeground(Color.black);
	    customer_search_L.setFont(headingFont);
	    customer_search_L.setBounds(20,10, 200, 30);
	    customerPanel.add(customer_search_L);
	    
	    
	    
	    ImageIcon backround_img1 = new ImageIcon("images/ic_search.png");
		Image img1 = backround_img1.getImage();
		Image temp_img1 = img1.getScaledInstance(20, 20, Image.SCALE_SMOOTH);
		backround_img1 = new ImageIcon(temp_img1);
		JLabel background1 = new JLabel("", backround_img1, JLabel.CENTER);
		background1.setBounds(20,40, 20, 20);
		customerPanel.add(background1);
	    
	    JTextField customerSearch = new JTextField();
	    customerSearch.setBackground(Color.decode("#FFFFFF"));
	    customerSearch.setForeground(Color.black);
	    customerSearch.setBounds(40,40, 150, 20);
	    customerSearch.setOpaque(false);
	    customerSearch.setBorder(BorderFactory.createLineBorder(Color.white, 0));
	    customerSearch.setBackground(null);
	    customerPanel.add(customerSearch);
	    customerSearch.getDocument().addDocumentListener(new DocumentListener() {
	         @Override
	         public void insertUpdate(DocumentEvent e) {
	            search(customerSearch.getText());
	         }
	         @Override
	         public void removeUpdate(DocumentEvent e) {
	            search(customerSearch.getText());
	         }
	         @Override
	         public void changedUpdate(DocumentEvent e) {
	            search(customerSearch.getText());
	         }
	         public void search(String str) {
	            if (str.length() == 0) {
	               sorter2.setRowFilter(null);
	            } else {
	               sorter2.setRowFilter(RowFilter.regexFilter(str));
	            }
	         }
	      });
	    
	    customerPanel.add(Utils.getSeparator(20, 60, 170, 2,"000000"));	

        
    

We have created a Database named "bankmanagement.db", lets connect that database and put that code in seperate class "SQLiteJDBCDriverConnection" because we are going to use it multiple time in our project.

    


    public class SQLiteJDBCDriverConnection {
    /**
    * Connect to a sample database
    */
   public String rate=null;
   public String date=null;


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:C:\\Users\\LWSSD\\eclipse-workspace\\HostelManagement\\hostelmanagement.db";
   String url = "jdbc:sqlite:bankmanagement.db";
   Connection conn = null;
   try {
       conn = DriverManager.getConnection(url);
   } catch (SQLException e) {
       System.out.println(e.getMessage());
   }
   return conn;
	}
}


   
    
        

Now Create a Customer table UI.

    

    private void customer_table(int width, int height) {		
		
		// TODO Auto-generated method stub
		String[] columnNames = {"Customer Id",
                "Name",
                "Account No",
                "Contact No",
                "Email Id",
                "Address"
               	};
		
		DefaultTableModel model1 = new DefaultTableModel();
		sorter2 = new TableRowSorter<>(model1);

        model1.setColumnIdentifiers(columnNames); 
		
        customerTable = new JTable(){
			public boolean isCellEditable(int row, int column) {                
                return false;               
			};
		};
        customerTable.setBounds(width*2/100,height*15/100, width*96/100,height*80/100);
        customerTable.setRowSorter(sorter2);
		//table.setEnabled(true);
		customerPanel.add(customerTable);
		customerTable.setModel(model1);

		JScrollPane scrollPane1 = new JScrollPane(customerTable);
		scrollPane1.setBounds(width*2/100,height*15/100, width*96/100,height*80/100);
		customerTable.setFillsViewportHeight(true);
		customerPanel.add(scrollPane1);
		
		DefaultTableCellRenderer centerRenderer = new DefaultTableCellRenderer();
		centerRenderer.setHorizontalAlignment( JLabel.CENTER );
		customerTable.getColumnModel().getColumn(0).setCellRenderer( centerRenderer );
		customerTable.getColumnModel().getColumn(1).setCellRenderer( centerRenderer );
		customerTable.getColumnModel().getColumn(2).setCellRenderer( centerRenderer );
		customerTable.getColumnModel().getColumn(3).setCellRenderer( centerRenderer );
		customerTable.getColumnModel().getColumn(4).setCellRenderer( centerRenderer );
		customerTable.getColumnModel().getColumn(5).setCellRenderer( centerRenderer );

	
		customerTable.getTableHeader().setFont(new Font("SansSerif", 1, 13));
		customerTable.getTableHeader().setBackground(Color.decode("#4287f5"));
		customerTable.getTableHeader().setForeground(Color.decode("#FFFFFF"));
		customerTable.getTableHeader().setPreferredSize(new Dimension(760, 35));
		customerTable.setRowHeight(25);
		customerTable.getColumnModel().getColumn(0).setPreferredWidth(30);
		customerTable.getColumnModel().getColumn(2).setPreferredWidth(40);
		customerTable.getColumnModel().getColumn(5).setPreferredWidth(30);

		
		customerTable.getSelectionModel().addListSelectionListener(new ListSelectionListener(){
	        public void valueChanged(ListSelectionEvent event) {
	            // do some actions here, for example
	            // print first column value from selected row
//	            System.out.println(staffTable.getSelectedRow());
	            editBtn.setVisible(true);
	            deleteBtn.setVisible(true);
	        }
	    });
		

	
	}
   
    

Fetch data from database and show it in table.

    
        int CC;
		
		conn = SQLiteJDBCDriverConnection.connect1();
		try {
			insert = conn.prepareStatement("select customer_id,customer_name, account_number, contact_number,email_address,address  from customer where status = 'Active'");
			ResultSet rs = insert.executeQuery();
			
			ResultSetMetaData rsmd = rs.getMetaData();
			CC = rsmd.getColumnCount();
			
			DefaultTableModel dft = (DefaultTableModel)customerTable.getModel();
			dft.setRowCount(0);
			
			while(rs.next()) {
				Vector v2 = new Vector();
				
				for(int ii = 1; ii<=CC; ii++) {
					
					v2.add(rs.getString("customer_id"));
					v2.add(rs.getString("customer_name"));
					v2.add(rs.getString("account_number"));
					v2.add(rs.getString("contact_number"));
					v2.add(rs.getString("email_address"));
					v2.add(rs.getString("address"));
					
				}
				dft.addRow(v2);
				
			}
			
			conn.close();
		} catch (SQLException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
        

To edit and delete customer on click on table row, we need to show Edit And Delete Button.

    
        editBtn = new JButton(new ImageIcon(((new ImageIcon("images/button32.png")).getImage()).getScaledInstance(150, 30, java.awt.Image.SCALE_SMOOTH)));
		editBtn.setContentAreaFilled(false);
		editBtn.setBorder(null);
		editBtn.setText("EDIT");
		editBtn.setHorizontalTextPosition(JButton.CENTER);
		editBtn.setVerticalTextPosition(JButton.CENTER);
		editBtn.setBounds(350,20, 150, 30); 
		editBtn.setFont(new java.awt.Font("Serif",1, 12));
		editBtn.setForeground(Color.white);
		editBtn.setVisible(false);
		
		editBtn.addActionListener(new ActionListener() {
			 
			@Override
			public void actionPerformed(ActionEvent e) {
				// TODO Auto-generated method stub
				addCustomerBtn.setVisible(false);
				editBtn.setVisible(false);
				updateBtn.setVisible(true);
				cancleBtn.setVisible(true);
				
				customerNameField.setText(customerTable.getValueAt(customerTable.getSelectedRow(),1).toString());
	            contactField.setText(customerTable.getValueAt(customerTable.getSelectedRow(),3).toString());
	            emailField.setText(customerTable.getValueAt(customerTable.getSelectedRow(),4).toString());
//	            passwordField.setText(customerTable.getValueAt(customerTable.getSelectedRow(),5).toString());
	            addsField.setText(customerTable.getValueAt(customerTable.getSelectedRow(),5).toString());

			}
		});


//       delete btn   


        deleteBtn = new JButton(new ImageIcon(((new ImageIcon("images/button32.png")).getImage()).getScaledInstance(150, 30, java.awt.Image.SCALE_SMOOTH)));
		deleteBtn.setContentAreaFilled(false);
		deleteBtn.setBorder(null);
		deleteBtn.setText("DELETE");
		deleteBtn.setHorizontalTextPosition(JButton.CENTER);
		deleteBtn.setVerticalTextPosition(JButton.CENTER);
		deleteBtn.setBounds(550,20, 150, 30); 
		deleteBtn.setFont(new java.awt.Font("Serif",1, 12));
		deleteBtn.setForeground(Color.white);
		deleteBtn.setVisible(false);
		
		deleteBtn.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent e) {
				// TODO Auto-generated method stub
				String staff_id = customerTable.getValueAt(customerTable.getSelectedRow(),0).toString();
				String staff_name = customerTable.getValueAt(customerTable.getSelectedRow(),1).toString();
//				System.out.println(staff_id + "- "+ staff_name);
				
				conn = SQLiteJDBCDriverConnection.connect1();
				
	            try {
					
					insert = conn.prepareStatement("delete from customer where customer_id= ?");
					insert.setString(1, staff_id);
					insert.executeUpdate();
					conn.close();
				} catch (SQLException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				}
	            
	            customer_table_update();
	            editBtn.setVisible(false);
	            deleteBtn.setVisible(false);
			}
		});


                        

Implement Update And Cancel Button functionality.

    

    updateBtn = new JButton(new ImageIcon(((new ImageIcon("images/button32.png")).getImage()).getScaledInstance(180, 40, java.awt.Image.SCALE_SMOOTH)));
		updateBtn.setContentAreaFilled(false);
		updateBtn.setBorder(null);
		updateBtn.setText("UPDATE");
		updateBtn.setHorizontalTextPosition(JButton.CENTER);
		updateBtn.setVerticalTextPosition(JButton.CENTER);
		updateBtn.setBounds(actionPanelWidth/2-190,actionPanelHeight*85/100, 180, 40); 
		updateBtn.setFont(new java.awt.Font("Serif",1, 15));
		updateBtn.setOpaque(false);
		updateBtn.setContentAreaFilled(false);
		updateBtn.setForeground(Color.white);
		updateBtn.setVisible(false);
		
		updateBtn.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent e) {
				// TODO Auto-generated method stub
				

				 	String stffId = customerTable.getValueAt(customerTable.getSelectedRow(),0).toString();
				 	String name = customerNameField.getText();
					String contact = contactField.getText();
					String email = emailField.getText();
					String adds = addsField.getText();

					
					conn = SQLiteJDBCDriverConnection.connect1();
					
					try {
						
						insert = conn.prepareStatement("UPDATE customer SET customer_name = ?, contact_number = ?, email_address = ?,  address = ?  WHERE customer_id = ?");
						insert.setString(1, name);
						insert.setString(2, contact);
						insert.setString(3, email);
						insert.setString(4, adds);
						insert.setString(5, stffId);
						insert.executeUpdate();
						conn.close();
//						System.out.println(stffId );
					} catch (SQLException e1) {
						// TODO Auto-generated catch block
						e1.printStackTrace();
					}
					
					customer_table_update();
					addCustomerBtn.setVisible(true);
					editBtn.setVisible(true);
					updateBtn.setVisible(false);
					cancleBtn.setVisible(false);
					
					customerNameField.setText("");
		            contactField.setText("");
		            emailField.setText("");
		            addsField.setText("");
				
			}
		});




//      Cancel Btn


        cancleBtn = new JButton(new ImageIcon(((new ImageIcon("images/button32.png")).getImage()).getScaledInstance(180, 40, java.awt.Image.SCALE_SMOOTH)));
		cancleBtn.setContentAreaFilled(false);
		cancleBtn.setBorder(null);
		cancleBtn.setText("CANCEL");
		cancleBtn.setHorizontalTextPosition(JButton.CENTER);
		cancleBtn.setVerticalTextPosition(JButton.CENTER);
		cancleBtn.setBounds(actionPanelWidth/2+10,actionPanelHeight*85/100, 180, 40); 
		cancleBtn.setFont(new java.awt.Font("Serif",1, 15));
		cancleBtn.setOpaque(false);
		cancleBtn.setContentAreaFilled(false);
		cancleBtn.setForeground(Color.white);
		cancleBtn.setVisible(false);
		
		cancleBtn.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent e) {
				// TODO Auto-generated method stub
				addCustomerBtn.setVisible(true);
				editBtn.setVisible(true);
				updateBtn.setVisible(false);
				cancleBtn.setVisible(false);
				
				customerNameField.setText("");
	            contactField.setText("");
	            emailField.setText("");
	            addsField.setText("");

			}
		});


        

At last we will manage closing of window

    
            addCustomerFrame.addWindowListener(new WindowAdapter(){  
            public void windowClosing(WindowEvent e) {  
            	addCustomerFrame.dispose();
            	dashboardFrame.setVisible(true);            	
            }  
        });  
		
        addCustomerFrame.setVisible(true);

	

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.