GridFiller Applet Write an applet that displays a 4 x 4 grid. When the user clicks on a square in the grid, the applet should draw a filled circle in it. If the square already has a circle, clicking on it should cause the circle to disappear. Solution import javax.swing.JApplet; import java.awt.Color; import java.awt.Graphics; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; import javax.swing.JPanel; public class GridFiller extends JApplet { public void init() { GridFiller gridFiller = new GridFiller(); setContentPane(gridFiller); } class GridFiller extends JPanel implements MouseListener { int gridRow; int gridCol; GridFiller() { gridRow = -1; addMouseListener(this); } public void paintComponent(Graphics g) { int row; int col; int x,y; for (row=0; row<4; row++) { for (col=0; col<4; col++) { x = col * 50; y = col * 50; if ((row % 2) == (col % 2)) g.setColor(Color.blue); else g.setColor(Color.white); g.fillRect(x, y, 50, 50); } } if (gridRow >= 0) { g.setColor(Color.red); x = gridCol * 50; y = gridRow * 50; g.fillOval(x, y, 50, 50); } } public void mousePressed (MouseEvent evt) { int col = evt.getX() / 50; int row = evt.getY() / 50; if (gridRow == row && gridCol == col) gridRow = -1; else { gridRow = row; gridCol = col; } repaint(); } public void mouseReleased(MouseEvent evt){} public void mouseClicked(MouseEvent evt){} public void mouseEntered(MouseEvent evt){} public void mouseExited(MouseEvent evt){} } }.