Lights Off is a puzzle game consisting of an \$n\times n\$ grid of lights. At the beginning of the game, some of the lights are switched on. When a light is activated, it and its four neighbors in the cardinal directions are toggled. The objective is to turn off all the lights.Input:000110010Output should be 000000000by selecting cells \$(0,0)\$, \$(1,0)\$, \$(1,1)\$, \$(2,1)\$, and \$(2,2)\$I'd like to know if my code can be made any more efficient.import javax.swing.*;import java.awt.*;import javax.swing.JFrame;import java.util.Scanner;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;public class lightOff extends JFrame implements ActionListener{  public static final int W = 400;  public static final int H = 200;  JButton[][] lights = new JButton[3][3];  int COLS = 3, ROWS = 3;  public lightOff()  {      super(Light Off);       setSize(W,H);      setLayout(new GridLayout(3,3));      setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);      Scanner kb = new Scanner(System.in);      String[][] input = {{0,0,0},{1,1,0},{0,1,0}};      for(int i=0;i<3;i++)       {         for(int j=0;j<3;j++)          {            lights[i][j] = new JButton(); // Initializing all JButton            lights[i][j].addActionListener(this); // Registering listener             lights[i][j].setText(input[i][j]); // setting text of each                                                // button as per input String            add(lights[i][j]);  // adding JButton to the JFrame          }       }     }   public static void main(String[] args)    {       lightOff obj1 = new lightOff();       obj1.setVisible(true);    }   public void actionPerformed(ActionEvent e)   {       JButton action = (JButton)e.getSource();       if(action==lights[0][0])        {       if(0.equals(lights[0][0].getText()))          lights[0][0].setText(1);       else           lights[0][0].setText(0);         // edgeToggle(0,0,action);       forward(0,0);       down(0,0);       }      else if(action==lights[0][1])      {        if(lights[0][2].getText()==0)          lights[0][2].setText(1);        else           lights[0][2].setText(0);        backward(0,1);        forward(0,1);        down(0,1);   }   else if(action==lights[0][2])   {       if(lights[0][2].getText()==0)          lights[0][2].setText(1);       else           lights[0][2].setText(0);         // edgeToggle(0,2,action);       backward(0,2);       down(0,2);   }   else if(action==lights[1][0])   {     if(lights[1][0].getText()==0)          lights[1][0].setText(1);       else           lights[1][0].setText(0);     up(1,0);     down(1,0);     forward(1,0);   }   else if(action==lights[1][1])   {     if(lights[1][1].getText()==0)          lights[1][1].setText(1);       else           lights[1][1].setText(0);     up(1,1);     down(1,1);     backward(1,1);     forward(1,1);   }   else if(action==lights[1][2])   {     if(lights[1][2].getText()==0)          lights[1][2].setText(1);       else           lights[1][2].setText(0);     up(1,2);     down(1,2);     backward(1,2);   }   else if(action==lights[2][0])   {       if(lights[2][0].getText()==0)          lights[2][0].setText(1);       else           lights[2][0].setText(0);        //  edgeToggle(2,0,action);       up(2,0);       forward(2,0);   }   else if(action==lights[2][1])   {     if(lights[2][1].getText()==0)          lights[2][1].setText(1);       else           lights[2][1].setText(0);     up(2,1);     backward(2,1);     forward(2,1);   }   else if(action==lights[2][2])   {       if(lights[2][2].getText()==0)          lights[2][2].setText(1);       else           lights[2][2].setText(0);   //       edgeToggle(2,2,action);       up(2,2);       backward(2,2);   }   }   public void forward(int a, int b) // calling to check status                                      // of next Jbutton in same row   {      if(0.equals(lights[a][b+1].getText()))       lights[a][b+1].setText(1);      else       lights[a][b+1].setText(0);   }  public void backward(int a, int b) // calling to check status of previous                                      // JButton in same row.   {   if(0.equals(lights[a][b-1].getText()))       lights[a][b-1].setText(1);   else       lights[a][b-1].setText(0);   }   public void up(int a, int b) // calling to check status of Jbutton                                 // above the current one.   {   if(0.equals(lights[a-1][b].getText()))       lights[a-1][b].setText(1);   else       lights[a-1][b].setText(0);    }   public void down(int a, int b) // calling to check status of Jbutton                                  // below the currrent Jbutton.   {   if(0.equals(lights[a+1][b].getText()))       lights[a+1][b].setText(1);   else       lights[a+1][b].setText(0);   }   }
Lights off puzzle
java;performance;swing