Add/Edit Student

Add Hostel

Above UI we are going to create by AWT for adding student in our Hostel 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.

    
			JFrame frame = new JFrame("Add Student");
		    Utils.centeredFrame(frame, winWidth, winHeight, "Add/Edit Student");
		    frame.setResizable(false);

		    
	        Container mainContainer=frame.getContentPane();
	        mainContainer.setBackground(Color.gray);
	    	      

	        int panelWid = winWidth-winWidth/20;
		    int panelHig = winHeight-winHeight/10;
	    

	        JPanel panel = new JPanel();
	        panel.setLayout(null);
		    panel.setOpaque(false);
		    panel.setBackground(Color.BLACK);
		    panel.setSize(new Dimension(winWidth-winWidth/20,winHeight-winHeight/10));
		    panel.setLocation(winWidth/50,winHeight/40);
		    mainContainer.add(panel,BorderLayout.CENTER);
    

After creation of window, we will add a canvas background.

    
	JComponent jcomponent=new Background(winWidth/50,winHeight/40,(winWidth-winWidth/20),winHeight-winHeight/10);// 
	mainContainer.add(jcomponent,BorderLayout.CENTER);

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

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

    	}

    
	}
    

Once your window is created with custom background, we will create layouts with some reduced dimensions.

    
	leftside =  Utils.createPanel(winWidth/3,winHeight*7/10,new Point(winWidth/50,winHeight/6), true,"Action");
	panel.add(leftside,BorderLayout.NORTH);
	leftside.setLayout(null);
	leftside.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
	        
	rightside =  Utils.createPanel(winWidth*57/100,winHeight*7/10,new Point(winWidth/3+winWidth/30,winHeight/6), true,"Student Details");
	panel.add(rightside,BorderLayout.WEST);
	rightside.setLayout(null);

Now create heading UI and Lines for All Layout.

    
    	// for heading Layout
		Font headingFont1 = new Font("Lucida",Font.BOLD,22);
	    heading = new JLabel("Add/Edit Student");
	    heading.setHorizontalAlignment(JLabel.CENTER);
	    heading.setVerticalAlignment(JLabel.CENTER);
	    heading.setBackground(Color.decode("#80c2b2"));
	    heading.setForeground(Color.black);
	    heading.setFont(headingFont1);
	    heading.setBounds(0,panelHig/30, panelWid, panelHig/15);
	        
	    panel.add(heading);
	        
	        
	    JSeparator jSeparator1 = new JSeparator();
		jSeparator1.setBackground(Color.black);
		jSeparator1.setAlignmentX(JSeparator.CENTER_ALIGNMENT);
	    jSeparator1.setBounds(20, 80, winWidth-winWidth/12, panelHig/13);
	    panel.add(jSeparator1);
	        
	        
	    Border loweredetched = BorderFactory.createEtchedBorder(EtchedBorder.LOWERED);

	    //Lines
	    TitledBorder usernametittle = BorderFactory.createTitledBorder(loweredetched, "Student Name");
	    usernametittle.setTitleJustification(TitledBorder.LEFT);
	        
	        
	    TitledBorder emailtittle = BorderFactory.createTitledBorder(loweredetched, "Email");
	    emailtittle.setTitleJustification(TitledBorder.LEFT);
	        
	    TitledBorder phoneTittle = BorderFactory.createTitledBorder(loweredetched, "Contact No");
	    phoneTittle.setTitleJustification(TitledBorder.LEFT);
	        
	    TitledBorder searchTittle = BorderFactory.createTitledBorder(loweredetched, "Search");
	    searchTittle.setTitleJustification(TitledBorder.LEFT);
	        
	        
	        
        TitledBorder passwordTittled = BorderFactory.createTitledBorder(loweredetched, "Address");
        passwordTittled.setTitleJustification(TitledBorder.LEFT);
        
    

Here is Student UI in leftside layout.

     
		//Name  
    	name=new JLabel();
        name.setText("Student Name");
        name.setForeground(Color.black);
        name.setFont(new Font("Lucida",Font.PLAIN,12));
        name.setSize(new Dimension(winWidth/3,winHeight/10));
        name.setLocation(30, 30); 
    

	    myTextField = new JTextField();
	    myTextField.setSize(new Dimension(winWidth*3/10,winHeight/15));
	    myTextField.setLocation(30,40);	
	    myTextField.setBorder(usernametittle);
	    myTextField.setVisible(true);
	    leftside.add(myTextField);
	          
	    //Mail    
	    email=new JLabel();
	    email.setText("Enter Email");
	    email.setForeground(Color.black);
	    email.setFont(new Font("Lucida",Font.PLAIN,12));
	    email.setSize(new Dimension(winWidth/3,winHeight/10));
	    email.setLocation(30, 130); 

	    emailField = new JTextField();
	    emailField.setSize(new Dimension(winWidth*3/10,winHeight/15));
	    emailField.setLocation(30,140);	
	    emailField.setBorder(emailtittle);
	    leftside.add(emailField,BorderLayout.SOUTH);

	    //Phone 
	    phone=new JLabel();
	    phone.setText("Enter Contact No");
	    phone.setForeground(Color.black);
	    phone.setFont(new Font("Lucida",Font.PLAIN,12));
	    phone.setSize(new Dimension(winWidth/3,winHeight/10));
	    phone.setLocation(30, 230); 

	    phonetextField = new JTextField();
	    phonetextField.setSize(new Dimension(winWidth*3/10,winHeight/15));
	    phonetextField.setLocation(30,240);	
	    phonetextField.setBorder(phoneTittle);
	    leftside.add(phonetextField,BorderLayout.SOUTH);

		//Password
	    password=new JLabel();
	    password.setText("Assign a password");
	    password.setForeground(Color.black);
	    password.setFont(new Font("Lucida",Font.PLAIN,12));
	    password.setSize(new Dimension(winWidth/3,winHeight/10));
	    password.setLocation(30, 330);   
	       

	    addstextField = new JTextField();
	    addstextField.setSize(new Dimension(winWidth*3/10,winHeight/15));
	    addstextField.setLocation(30,340);	
	    addstextField.setBorder(passwordTittled);
	    leftside.add(addstextField,BorderLayout.SOUTH);
        
    

Here is "Add Student" Button in leftside layout and logic for add student in database when click "Add Student" Button:

    
    	addButton = new JButton(new ImageIcon(((new ImageIcon("images/button32.png")).getImage()).getScaledInstance(200, 50, java.awt.Image.SCALE_SMOOTH)));      
	        addButton.setText("Add Student");
	        addButton.setContentAreaFilled(false);
	        addButton.setBorder(null);
	        addButton.setForeground(Color.white);
	        addButton.setHorizontalTextPosition(JButton.CENTER);
	        addButton.setVerticalTextPosition(JButton.CENTER);
	        addButton.setFont(new Font("Lucida",Font.PLAIN,16));
	        addButton.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
	        addButton.setBounds(130,450, 200, 50);

	        
	        leftside.add(addButton);
	        addButton.addActionListener(new ActionListener() {
	            @Override
	            public void actionPerformed(ActionEvent ae) {
	            	
	            	String  var = "";
	            	String nameTxt = "";
					String emailTxt = "";
					String contNoTxt = "";
					String addsTxt = "";
					String student_id;
					Boolean room_alloted = false;
					Boolean is_name_entered = false;
					Boolean is_adds_entered = false;
					Boolean is_cont_entered = false;
					Boolean is_email_entered = false;
					
					if(myTextField.getText().equalsIgnoreCase("") || myTextField.getText().equalsIgnoreCase(" ")){
						var += "Name Should not be empty, ";
					}else {
						
						nameTxt = myTextField.getText();
						is_name_entered = true;
					}
					
					if(emailField.getText().equalsIgnoreCase("") || emailField.getText().equalsIgnoreCase(" ")){
						var += "Email Should not be empty, ";
					}else {
						
						emailTxt = emailField.getText();
						is_email_entered = true;
					}
					
					if(phonetextField.getText().equalsIgnoreCase("") || phonetextField.getText().equalsIgnoreCase(" ")){
						var += "Contact Should not be empty, ";
					}else {
						
						contNoTxt = phonetextField.getText();
						is_cont_entered = true;
					}
					
					if(addstextField.getText().equalsIgnoreCase("") || addstextField.getText().equalsIgnoreCase(" ")){
						var += "Address Should not be empty, ";
					}else {
						
						addsTxt = addstextField.getText();
						is_adds_entered = true;
					}
					
					
	            	
	            	Connection conn = SQLiteJDBCDriverConnection.connect1();
	             	
	            	if(is_name_entered && is_email_entered && is_cont_entered && is_adds_entered) {
	            		
	            		
	            		try {
		            		
		            		String key1 = "STUDENT_LAST_COUNT";
		            		String sql = "SELECT value from system_setting where key like '%"+key1+"%';";

		            		Statement stmt  = conn.createStatement();
		            	    ResultSet rs    = stmt.executeQuery(sql);
		            		
		            	  	int id_count = Utils.convert_string_to_int(rs.getString("value")) + 1;

		            	    student_id = get_student_id(id_count) + String.valueOf(id_count);
		            	    
		            		
							PreparedStatement insert = conn
									.prepareStatement("insert into student(student_id,student_name,contact_no,email_id,address,room_alloted)values(?,?,?,?,?,?)");
							insert.setString(1, student_id);
							insert.setString(2, nameTxt);
							insert.setString(3, contNoTxt);
							insert.setString(4, emailTxt);
							insert.setString(5, addsTxt);
							insert.setBoolean(6, room_alloted);
							

							insert.executeUpdate();
							JOptionPane.showMessageDialog(null, "Submit successfully");

							myTextField.setText("");
							emailField.setText("");
							phonetextField.setText("");
							addstextField.setText("");
							student_table_update();
							
							 String query = "update system_setting set value = ? where key = ?";
		            	     PreparedStatement preparedStmt = conn.prepareStatement(query);
		            	     preparedStmt.setInt(1, id_count);
		            	     preparedStmt.setString(2, key1);

		            	     preparedStmt.executeUpdate();
    
							conn.close();	
							
						} catch (SQLException e1) {
							// TODO Auto-generated catch block
							e1.printStackTrace();
						}
	            		
	            				
	            	}else {
	            		
	            	      JOptionPane.showMessageDialog(null, var,"Error message", JOptionPane.ERROR_MESSAGE);

	            	}
	
     	
	            }
	        });	        	       
	        panel.revalidate();
	        panel.repaint();   
	        

Add "UPDATE" and "CANCLE" Button in Leftside Layout ,when Select any student from student table and click "EDIT" Button and Also here is logic for update studentdetails in database when click "UPDATE" Button or clear all entery field when click "CACLE" Button.

    
	updatecalBtn();


	//logic
	private void updatecalBtn() {
		 
		 
		 
		updateBtn = new JButton(new ImageIcon(((new ImageIcon("images/button32.png")).getImage()).getScaledInstance(150, 40, java.awt.Image.SCALE_SMOOTH)));      
		updateBtn.setText("Update");
		updateBtn.setContentAreaFilled(false);
		updateBtn.setBorder(null);
		updateBtn.setForeground(Color.white);
		updateBtn.setHorizontalTextPosition(JButton.CENTER);
		updateBtn.setVerticalTextPosition(JButton.CENTER);
		updateBtn.setFont(new Font("Lucida",Font.PLAIN,16));
		updateBtn.setBounds(50,450, 150, 40);
		updateBtn.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
		updateBtn.setVisible(false);
		leftside.add(updateBtn);  
		
		
		cancelBtn = new JButton(new ImageIcon(((new ImageIcon("images/button32.png")).getImage()).getScaledInstance(150, 40, java.awt.Image.SCALE_SMOOTH)));      
		cancelBtn.setText("Cancel");
		cancelBtn.setContentAreaFilled(false);
		cancelBtn.setBorder(null);
		cancelBtn.setForeground(Color.white);
		cancelBtn.setHorizontalTextPosition(JButton.CENTER);
		cancelBtn.setVerticalTextPosition(JButton.CENTER);
		cancelBtn.setFont(new Font("Lucida",Font.PLAIN,16));
		cancelBtn.setBounds(250,450, 150, 40);
		cancelBtn.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
		cancelBtn.setVisible(false);
		leftside.add(cancelBtn);
		
		
		updateBtn.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent ae) {
				
				String nameTxt = myTextField.getText();
				String emailTxt = emailField.getText();
				String contNoTxt = phonetextField.getText();
				String addsTxt = addstextField.getText();
				
				
				Connection conn = SQLiteJDBCDriverConnection.connect1();
				

				
				try {
					
					
					 String query = "update student set student_name = ?, contact_no = ?, email_id = ?, address = ? where student_id = ?";
					 PreparedStatement preparedStmt = conn.prepareStatement(query);
					 preparedStmt.setString(1, nameTxt);
					 preparedStmt.setString(2, contNoTxt);
					 preparedStmt.setString(3, emailTxt);
					 preparedStmt.setString(4, addsTxt);
					 preparedStmt.setString(5, studentTable.getValueAt(studentTable.getSelectedRow(),0).toString());

					 preparedStmt.executeUpdate();

					 JOptionPane.showMessageDialog(null, "Updated Successfully!","Updated", JOptionPane.INFORMATION_MESSAGE);
//	            	     JOptionPane.showMessageDialog(null,"Updated", "Updated Successfully!");
					  
					 myTextField.setText("");
					   emailField.setText("");
					   phonetextField.setText("");
					   addstextField.setText("");
					  
					 conn.close();
					
					 student_table_update();
				
					
				} catch (SQLException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				}
				
			   
				addButton.setVisible(true);
				cancelBtn.setVisible(false);
				updateBtn.setVisible(false);
				
				
			}
		});	        
		
	
		cancelBtn.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent ae) {
				
				
				myTextField.setText("");
				emailField.setText("");
				phonetextField.setText("");
				addstextField.setText("");
				
				
				addButton.setVisible(true);
				cancelBtn.setVisible(false);
				updateBtn.setVisible(false);
				editBtn.setVisible(true);
				deleteBtn.setVisible(true);
				
			}
		});	        
	
	}

Create search UI on the rightside layout and logic for search data.

    
	Font headingFont = new Font("Lucida",Font.BOLD,12);
	JLabel searchLabel = new JLabel("Search Student");
	searchLabel.setAlignmentX(JLabel.LEFT);

	searchLabel.setForeground(Color.black);
	searchLabel.setFont(headingFont);
	searchLabel.setBounds(20,40, 150, 30);
	rightside.add(searchLabel);
		    
	ImageIcon backround_img = new ImageIcon("images/ic_search.png");
	Image img = backround_img.getImage();
	Image temp_img = img.getScaledInstance(20, 20, Image.SCALE_SMOOTH);
	backround_img = new ImageIcon(temp_img);
	JLabel background = new JLabel("", backround_img, JLabel.CENTER);
	background.setBounds(20,80, 20, 20);
	rightside.add(background);
		    
	JTextField studentSearch = new JTextField(15);
	studentSearch.setBackground(Color.decode("#FFFFFF"));
	studentSearch.setForeground(Color.black);
	studentSearch.setBounds(40,80, 150, 20);
	rightside.add(studentSearch);
		    
	studentSearch.getDocument().addDocumentListener(new DocumentListener() {
		@Override
		public void insertUpdate(DocumentEvent e) {
		    search(studentSearch.getText());
		}
		@Override
		public void removeUpdate(DocumentEvent e) {
		    search(studentSearch.getText());
		}
		@Override
		public void changedUpdate(DocumentEvent e) {
		    search(studentSearch.getText());
		}
		public void search(String str) {
		    if (str.length() == 0) {
		        sorter.setRowFilter(null);
		    } else {
		        sorter.setRowFilter(RowFilter.regexFilter(str));
		    }
		}
	});
    

Here is Student table and logic for "EDIT" and "DELETE" button visible in search layout when select any customer:

    
    student_table();

	//Logic
    private void student_table() {		
			
			// TODO Auto-generated method stub
			String[] columnNames = {"Student Id",
	                "Name",
	                "Contact No",
	                "Email Id",
	                "Address"
	                };
			
			DefaultTableModel model = new DefaultTableModel();
			sorter = new TableRowSorter<>(model);

	        model.setColumnIdentifiers(columnNames); 
			
			studentTable = new JTable();
			studentTable.setRowSorter(sorter);
			studentTable.setBounds(15,120, winWidth*55/100, winHeight*7/15);
			
			rightside.add(studentTable);
			rightside.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
			studentTable.setModel(model);

			JScrollPane scrollPane = new JScrollPane(studentTable);
			scrollPane.setBounds(15,120, winWidth*55/100,winHeight*7/15);
			studentTable.setFillsViewportHeight(true);
			rightside.add(scrollPane);
			
			DefaultTableCellRenderer centerRenderer = new DefaultTableCellRenderer();
			centerRenderer.setHorizontalAlignment( JLabel.CENTER );
			studentTable.getColumnModel().getColumn(0).setCellRenderer( centerRenderer );
			studentTable.getColumnModel().getColumn(1).setCellRenderer( centerRenderer );
			studentTable.getColumnModel().getColumn(2).setCellRenderer( centerRenderer );
			studentTable.getColumnModel().getColumn(3).setCellRenderer( centerRenderer );
			studentTable.getColumnModel().getColumn(4).setCellRenderer( centerRenderer );
			
			
		
			studentTable.getTableHeader().setFont(new Font("SansSerif", 1, 13));
			studentTable.getTableHeader().setBackground(Color.decode("#4287f5"));
			studentTable.getTableHeader().setForeground(Color.decode("#FFFFFF"));
			
			studentTable.getColumnModel().getColumn(0).setPreferredWidth(30);
			studentTable.getColumnModel().getColumn(4).setPreferredWidth(30);
			studentTable.getColumnModel().getColumn(2).setPreferredWidth(40);
			
			studentTable.setRowHeight(30);
			

			
			 studentTable.getSelectionModel().addListSelectionListener(new ListSelectionListener(){
			        public void valueChanged(ListSelectionEvent event) {
			            
			            editBtn.setVisible(true);
			            deleteBtn.setVisible(true);
				           
			        }
		
			    });
			
			student_table_update();
		
	}
        

Here is logic of fetch data from database and update in student table.

    
	private void student_table_update() {		
			
			int CC;
			
			Connection conn = SQLiteJDBCDriverConnection.connect1();
			try {
				
				PreparedStatement insert = conn.prepareStatement("select student_id, student_name, contact_no, email_id, address  from student");
				ResultSet rs = insert.executeQuery();
				
				ResultSetMetaData rsmd = rs.getMetaData();
				CC = rsmd.getColumnCount();
				
				DefaultTableModel dft = (DefaultTableModel)studentTable.getModel();
				dft.setRowCount(0);
				
				while(rs.next()) {
					Vector v2 = new Vector();
					
					for(int ii = 1; ii<=CC; ii++) {
						
						v2.add(rs.getString("student_id"));
						v2.add(rs.getString("student_name"));
						v2.add(rs.getString("contact_no"));
						v2.add(rs.getString("email_id"));
						v2.add(rs.getString("address"));
						
					}
					dft.addRow(v2);
					
				}
				
				conn.close();
			} catch (SQLException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			}
			
		}
	  
	 public static String get_student_id(int s_id){
			
			String student_id = "STD";
			int count = 0;
			
			 if (s_id == 0) {
				 count = 1;
			 }
			 
			 while(s_id > 0) {
				 count = count + 1;
				 s_id = s_id / 10;
				 count = 3 - count;
				 
			 }
			 
			 while(count > 0) {
				 student_id = student_id + "0";
				 count = count - 1;
			 }
			 
			 return student_id;
		}		

Here is add "EDIT" and "DELETE" Button in rightside layout and logic for visible "UPDATE" and "CANCEL" Buttons in leftside layout when we select a student and click "EDIT" Button.Also logic for delete selected student when click "DELETE" Button.

    
    private void editdelBtn() {
		 
		editBtn = new JButton(new ImageIcon(((new ImageIcon("images/button32.png")).getImage()).getScaledInstance(150, 40, java.awt.Image.SCALE_SMOOTH)));      
		editBtn.setText("Edit");
		editBtn.setContentAreaFilled(false);
		editBtn.setBorder(null);
		editBtn.setForeground(Color.white);
		editBtn.setHorizontalTextPosition(JButton.CENTER);
		editBtn.setVerticalTextPosition(JButton.CENTER);
		editBtn.setFont(new Font("Lucida",Font.PLAIN,16));
		editBtn.setBounds(300,60, 150, 40);
		editBtn.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
		editBtn.setVisible(false);
		rightside.add(editBtn);  


		deleteBtn = new JButton(new ImageIcon(((new ImageIcon("images/button32.png")).getImage()).getScaledInstance(150, 40, java.awt.Image.SCALE_SMOOTH)));      
		deleteBtn.setText("Delete");
		deleteBtn.setContentAreaFilled(false);
		deleteBtn.setBorder(null);
		deleteBtn.setForeground(Color.white);
		deleteBtn.setHorizontalTextPosition(JButton.CENTER);
		deleteBtn.setVerticalTextPosition(JButton.CENTER);
		deleteBtn.setFont(new Font("Lucida",Font.PLAIN,16));
		deleteBtn.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
		deleteBtn.setBounds(500,60, 150, 40);
		deleteBtn.setVisible(false);
		rightside.add(deleteBtn);


		editBtn.addActionListener(new ActionListener() {
   			@Override
   			public void actionPerformed(ActionEvent ae) {
	   
	   			selected_std_id = studentTable.getValueAt(studentTable.getSelectedRow(),0).toString();
	   			myTextField.setText(studentTable.getValueAt(studentTable.getSelectedRow(),1).toString());
	   			phonetextField.setText(studentTable.getValueAt(studentTable.getSelectedRow(),2).toString());
	   			emailField.setText(studentTable.getValueAt(studentTable.getSelectedRow(),3).toString());
	   			addstextField.setText(studentTable.getValueAt(studentTable.getSelectedRow(),4).toString());
	   
	   			cancelBtn.setVisible(true);
	   			updateBtn.setVisible(true);
	   			addButton.setVisible(false);
	   			editBtn.setVisible(false);
	   			deleteBtn.setVisible(false);
	   
   			}
		});	        

		deleteBtn.addActionListener(new ActionListener() {
   			@Override
   			public void actionPerformed(ActionEvent ae) {
	   
	   			Connection conn = SQLiteJDBCDriverConnection.connect1();
	   
	   			try {
		   
		   
		   			int result = JOptionPane.showConfirmDialog(null, "Do you want to delete student record now?");
		   
		   			if(result == JOptionPane.YES_OPTION) {
			   
			   			String sql = "DELETE FROM student  WHERE student_id LIKE '%"+studentTable.getValueAt(studentTable.getSelectedRow(),0).toString()+"%'";

			   			Statement stmt  = conn.createStatement();
			   			int w = stmt.executeUpdate(sql);
			   
		   
			   			conn.close();
			   
			   			student_table_update();
			   
			   
						cancelBtn.setVisible(false);
						updateBtn.setVisible(false);
						addButton.setVisible(true);
						editBtn.setVisible(false);
						deleteBtn.setVisible(false);
			   
			   
		   			}
		
			
		   
	   			} catch (SQLException e1) {
		   			// TODO Auto-generated catch block
		   			e1.printStackTrace();
	   			}   
	   
   			}
		});	        


	}
 		
			

Here's logic for move table rows.

    
    public void tableChanged(TableModelEvent e) {
			// TODO Auto-generated method stub
			int row = e.getFirstRow();
	        int column = e.getColumn();
	        TableModel model = (TableModel)e.getSource();
	        String columnName = model.getColumnName(column);
	        Object data = model.getValueAt(row, column);
	        

	       System.out.println(columnName+data+"Wrong");
		}
            

At last here is frame visibility.

    
    frame.getContentPane().setBackground(Color.gray);
	        
	frame.addWindowListener(new WindowAdapter(){  
	    public void windowClosing(WindowEvent e) {  
	        frame.dispose();
	        dashboardFrame.setVisible(true);
	    }  
	});  
			
	frame.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.