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

public class TypingGame {
  public static final int MAX_COUNTER = 150;
  public static final int MAX_SIZE = 10;
  public static final int INTERVAL = 200;
  public static void main(String[] args) {
    JFrame frame = new JFrame();
    final ArrayList<Character> charList = new ArrayList<>();
    frame.addKeyListener(new KeyAdapter() {
      public void keyPressed(KeyEvent e) {
        char c = e.getKeyChar();
        if (charList.contains(c)) {
          charList.remove((Character) c);
        }
        System.out.println(charList);
      }
    });
    Timer t = new Timer(INTERVAL, new ActionListener() {
      int counter = 0;
      public void actionPerformed(ActionEvent e) {
        charList.add((char) ('a' + (int) ((Math.random() * 26))));
        System.out.println(charList);
        counter++;
        if (counter == MAX_COUNTER){
          System.out.println("You win!");
          System.exit(0);
        }
        if(charList.size()>MAX_SIZE){
          System.out.println("You lose!");
          System.exit(0);
        }
      }
    });
    t.start();
    frame.setSize(200, 200);
    frame.setVisible(true);
  }
}