Christian Joe B Andrew T Arthi Yinan Max Keqin Seth E Jared P Mike C Arif D He H
Rerajitha Siddartha Alex Q Sunghyun Brandon P Kevin S Andrew R Rajeev Matt Lonis
Xing W Xinyu Z Zhiwei Haoyang Hu Vanessa A Alex Stilian Levi R Chenrui He Kayl W 
Jiahao C David Jaehak Lee Jerry Haoxuan Shen 

Today we are going to talk about timers. 

To obtain a Scanner object we need the class java.util.Scanner as we know. 

Is Timer a class in java.util that I need to be aware of? 

https://docs.oracle.com/javase/tutorial/uiswing/misc/timer.html

We will be using the javax.swing.Timer class to keep track of time. 

public class One {
  public static void main(String[] args) {
    Timer t = new Timer(..., ...); 
    t.start(); 
  }
}

I need to work out some details. 

import java.awt.event.ActionListener; 
// https://docs.oracle.com/javase/8/docs/api/java/awt/event/ActionListener.html
import java.awt.event.ActionEvent; 

public class Umpire implements ActionListener {
  public void actionPerformed(ActionEvent e) {
    System.out.println("I can see it: " + e);  
  }
}

This is what an action listener looks like. 

Note the import statements. 

import javax.swing.Timer; 

public class One {
  public static void main(String[] args) {
    Umpire a = new Umpire(); // instantiate the class create an object 
    Timer t = new Timer(200, a); 
    t.start(); 
  }
}

Let's run this. 

import java.awt.event.ActionListener; 
// https://docs.oracle.com/javase/8/docs/api/java/awt/event/ActionListener.html
import java.awt.event.ActionEvent; 

public class Umpire implements ActionListener {
  int i; // initialized at zero
  public void actionPerformed(ActionEvent e) {
    this.i += 1; 
    System.out.println("The count is: " + this.i);  
  }
}

import javax.swing.Timer; 

public class One {
  public static void main(String[] args) {
    Umpire a = new Umpire(); // instantiate the class create an object 
    Timer t = new Timer(1000, a); 
    t.start(); 
  }
}

Where's the BigBang. 

Let's talk keyboard events. 

Timers are the source of ticks (action events). 

Key events are coming from the user. 

Letters that are not in there: a 

import javax.swing.JFrame; 

public class Andy extends JFrame {
  public Andy() {
    super(); 
    
  }
  public static void main(String[] args) {
    JFrame a = new Andy();  
    // System.out.println( a ); 
    a.setVisible( true ); 
    a.setSize(200, 400); 
  }
}

I can modify this a little:

import javax.swing.JFrame; 

public class Andy extends JFrame {
  public Andy() {
    super(); 
    this.setVisible(true);     
  }
  public static void main(String[] args) {
    JFrame a = new Andy();  
    // System.out.println( a ); 
    a.setSize(200, 400); 
  }
}

Here I define a key listener to get started: 

import java.awt.event.KeyListener; 
import java.awt.event.KeyEvent;

public class Something implements KeyListener {
  public void keyPressed(KeyEvent e){ }  
  public void keyReleased(KeyEvent e) { }
  public void keyTyped(KeyEvent e) { }
}

How can I connect them? 

import javax.swing.JFrame; 

public class Andy extends JFrame {
  public Andy() {
    super(); 
    this.setVisible(true);   
    this.setSize(200, 400); 
  }
  public static void main(String[] args) {
    JFrame a = new Andy();  
    // System.out.println( a ); 
    a.addKeyListener( new Something() ); 

  }
}

import java.awt.event.KeyListener; 
import java.awt.event.KeyEvent;

public class Something implements KeyListener {
  public void keyPressed(KeyEvent e){ 
    System.out.println("Ouch: " + e); 
  }  
  public void keyReleased(KeyEvent e) { }
  public void keyTyped(KeyEvent e) { }
}

--