previous
contents
next

The background method

  public void update(Graphics g) {
    background(g); // This line is new
    paint(g);
  }
  void background(Graphics g) {
       int width = getSize().width;
       int height = getSize().height;
       int squareSize = 2 * model.BALL_SIZE;
       
       g.setColor(Color.blue);
       g.fillRect(0, 0, width, height);
       g.setColor(Color.green);
       for (int x = 0; x < width; x += 2 * squareSize) {
           for (int y = 0; y < height; y += 2 * squareSize) {
               g.fillRect(x, y, squareSize, squareSize);
               g.fillRect(x + squareSize, y + squareSize,
                             squareSize, squareSize);
           }
       }
   }