Example 2: In this example, we will create a JTable with some data and highlight the row that the user clicks on, using the rowAtPoint method to determine which row was clicked.java import javax.swing.*; import java.awt.*; import java.awt.event.*; public class Example2 extends JFrame implements MouseListener { private JTable table; private int clickedRow = -1; public Example2() { // Create the data for the table Object[][] data = { { "John", "Doe", "45" }, { "Jane", "Doe", "42" }, { "Bob", "Smith", "23" } }; // Create the column names for the table String[] columns = { "First Name", "Last Name", "Age" }; // Create the table table = new JTable(data, columns); // Add the mouse listener to the table table.addMouseListener(this); // Add the table to the frame add(new JScrollPane(table)); setSize(300, 200); setVisible(true); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } // Implement the mouse listener methods public void mouseClicked(MouseEvent e) { // Get the point where the mouse was clicked Point point = e.getPoint(); // Get the row index at the clicked point int rowIndex = table.rowAtPoint(point); // If this is the first click and a row was clicked if (clickedRow == -1 && rowIndex != -1) { // Highlight the row table.setSelectionBackground(Color.YELLOW); table.setSelectionForeground(Color.BLACK); table.setRowSelectionInterval(rowIndex, rowIndex); clickedRow = rowIndex; } // If this is a subsequent click on the same row else if (clickedRow == rowIndex) { // Unhighlight the row table.setSelectionBackground(table.getBackground()); table.setSelectionForeground(table.getForeground()); table.clearSelection(); clickedRow = -1; } // If this is a click on a different row else { // Unhighlight the previous row table.setSelectionBackground(table.getBackground()); table.setSelectionForeground(table.getForeground()); table.clearSelection(); // Highlight the new row table.setSelectionBackground(Color.YELLOW); table.setSelectionForeground(Color.BLACK); table.setRowSelectionInterval(rowIndex, rowIndex); clickedRow = rowIndex; } } public void mouseEntered(MouseEvent e) {} public void mouseExited(MouseEvent e) {} public void mousePressed(MouseEvent e) {} public void mouseReleased(MouseEvent e) {} public static void main(String[] args) { new Example2(); } } ``` Both of these examples use the javax.swing JTable library package.