How should we start? 

If you're looking for a finished game:

http://silo.cs.indiana.edu:8346/c212/spr2014/tetris/tutorial.phps

Comments on those three classes:

http://zetcode.com/tutorials/javagamestutorial/tetris/

Our development today will follow: 

https://www.cs.indiana.edu/classes/c212/spr2014/final/stageOne/

So how should we start? 

We start with two classes:

import javax.swing.*; 

class Game extends JFrame {
  Game() {
    this.add(new World()); 
    this.setSize(200, 400);
    this.setVisible(true); 
    this.setDefaultCloseOperation(EXIT_ON_CLOSE); 
  }
  public static void main(String[] args) {
    Game game = new Game();  
  }
}

import javax.swing.*; 
import java.awt.*; 

class World extends JComponent {
  int count;
  World() {
    
  }
  public void paintComponent(Graphics g) {
    this.count += 1;
    System.out.println( "paintComponent called " + this.count + " times."); 
  }
}

So we compile Game.java and run it resize the frame see what happens. 

A Game is a World with time. 

A Game is responsible for the user interface.

The World provides its own timer. 

import javax.swing.*; 

class Game extends JFrame {
  Game() {
    World world = new World(); 
    this.add(world); 
    this.addKeyListener(world); 
    this.setSize(200, 400);
    this.setVisible(true); 
    this.setDefaultCloseOperation(EXIT_ON_CLOSE); 
  }
  public static void main(String[] args) {
    Game game = new Game();  
  }
}

The game has not changed at all at this stage. 

It was noticing and collecting key events all along.

The world is now longer in code to support actions based on those events:

import javax.swing.*; 
import java.awt.*; 
import java.awt.event.*;

class World extends JComponent implements KeyListener {
  public void keyPressed(KeyEvent e) {
    int keycode = e.getKeyCode();
    System.out.println("Ouch. You have typed: " + ((char) keycode)); 
    switch (keycode) {
      case KeyEvent.VK_LEFT: System.out.println("Left arrow key."); break; 
      case KeyEvent.VK_RIGHT: System.out.println("Right arrow key."); break; 
      case KeyEvent.VK_UP   : System.out.println("Up arrow key."); break; 
      case KeyEvent.VK_DOWN : System.out.println("Down arrow key."); break; 
      default      : System.out.println("No arrow key."); break; 
    }
  }
  public void keyReleased(KeyEvent e) { } 
  public void keyTyped(KeyEvent e) { } 
  int count;
  World() {
    
  }
  public void paintComponent(Graphics g) {
    this.count += 1;
    System.out.println( "paintComponent called " + this.count + " times."); 
  }
}

What about the timer? 

import javax.swing.*; 

class Game extends JFrame {
  Game() {
    World world = new World(); 
    this.add(world); 
    world.start(); 
    this.addKeyListener(world); 
    this.setSize(200, 400);
    this.setVisible(true); 
    this.setDefaultCloseOperation(EXIT_ON_CLOSE); 
  }
  public static void main(String[] args) {
    Game game = new Game();  
  }
}

Game still unchanged. 

The World now has a timer:

import javax.swing.*; 
import java.awt.*; 
import java.awt.event.*;

class World extends JComponent implements KeyListener, ActionListener {
  public void keyPressed(KeyEvent e) {
    int keycode = e.getKeyCode();
    System.out.println("Ouch. You have typed: " + ((char) keycode)); 
    switch (keycode) {
      case KeyEvent.VK_LEFT: System.out.println("Left arrow key."); break; 
      case KeyEvent.VK_RIGHT: System.out.println("Right arrow key."); break; 
      case KeyEvent.VK_UP   : System.out.println("Up arrow key."); break; 
      case KeyEvent.VK_DOWN : System.out.println("Down arrow key."); break; 
      default      : System.out.println("No arrow key."); break; 
    }
  }
  public void keyReleased(KeyEvent e) { } 
  public void keyTyped(KeyEvent e) { } 
  int count;
  Timer timer; 
  public void actionPerformed(ActionEvent e) {
    this.count += 1; 
    System.out.println( "ActionEvent received: " + this.count );  
  }
  World() {
    this.timer = new Timer(1000, this); 
  }
  void start() {
    this.timer.start();  
  }
  public void paintComponent(Graphics g) {
    // this.count += 1;
    // System.out.println( "paintComponent called " + this.count + " times."); 
    // g.drawString("paintComponent called " + this.count + " times.", 3, 50); 
  }
}

Now having set up the interface and the timer let's discuss the Shapes. 

(to be continued)