Create a Grid Layout and Light Toggling Buttons

Learn to add light buttons to grid layout.

Grid layout

A grid layout arranges components into a grid in which all components are the same size.

Adding LightButtons to Framed

  1. In framed.java, Add a private static final integer instance variable called GRIDSIZE, set to 3.
  2. Add a private LightButton two-dimensional array instance variable called lightButton, with GRIDSIZE rows and GRIDSIZE columns.
...
 
public class Framed extends JFrame {
  private static final long serialVersionUID = 1L;
  ____________________ GRIDSIZE = _____;
  ____________________[][] lightButton = ____________________;
 
    ...

Get hands-on with 1200+ tech skills courses.