----------------------------------------------------------------------------------------------------
import java.awt.Graphics; 
import java.awt.event.KeyEvent; 
import java.awt.event.MouseEvent; 

interface World {
  void draw(Graphics g);  
  void teh(); 
  void meh(MouseEvent e); 
  void keh(KeyEvent e); 
}
----------------------------------------------------------------------------------------------------
import javax.swing.*; 
import java.awt.*; 
import java.awt.event.*; 

public class BigBang extends JComponent implements ActionListener, 
                                                   MouseListener, 
                                                   KeyListener {
  Timer timer; 
  World world; 
  public BigBang(World world) {
    this.world = world; 
    this.timer = new Timer(500, this); 
    this.timer.start(); 
    this.addMouseListener(this); 
    this.addKeyListener(this); 
  }
  public void mouseEntered(MouseEvent e) { }
  public void mouseExited(MouseEvent e) { }
  public void mousePressed(MouseEvent e) { 
    this.world.meh(e); 
    this.repaint(); 
  }
  public void mouseReleased(MouseEvent e) { 

  }
  public void mouseClicked(MouseEvent e) { 
  
  }
  public void keyPressed(KeyEvent e) { 

  }
  public void keyReleased(KeyEvent e) { 

  } 
  public void keyTyped(KeyEvent e) { 
    this.world.keh(e);
    this.repaint();
  } 
  // int count;
  public void actionPerformed(ActionEvent e) {
    // this.count += 1; 
    // System.out.println("Ouch" + this.count);     
    this.world.teh();
  }
  public void paintComponent(Graphics g) {
    this.world.draw(g); 
  }
}
----------------------------------------------------------------------------------------------------
; the general framework is above (stays the same) 
; the specific application is defined below 
----------------------------------------------------------------------------------------------------
import javax.swing.JFrame; 
import java.awt.*;
import java.awt.event.*; 

public class Game implements World {
  Circle circle; 
  public Game() {
    this.circle = new Circle(200, 200, 30, Color.WHITE);  
  }
  int ticks; 
  public void teh() { 
    this.ticks += 1; 
    // System.out.println( "world reports: " + ticks );
  }
  public void draw(Graphics g) { 
    this.circle.draw(g); 
  } 
  public void meh(MouseEvent e) { 
    System.out.println("Mouse event detected."); 
  } 
  public void keh(KeyEvent e) { 
    System.out.println( "You have typed character: " + e.getKeyChar() ); 
    char c = e.getKeyChar(); 
    if (c == 'a') this.circle.move(-5, 0);
    else if (c == 'd') this.circle.move(5, 0); 
  }  
  public static void main(String[] args) {
     JFrame a = new JFrame(); 
     Game g = new Game(); 
     BigBang b = new BigBang( g ); 
     a.add( b ); 
     a.setVisible(true); 
     a.setSize(400, 400); 
     a.addKeyListener(b); 
  }
}
----------------------------------------------------------------------------------------------------
import java.awt.*; 

public class Circle {
  int x, y, radius;
  Color c;
  public Circle(int x, int y, int radius, Color c) {
    this.x = x; 
    this.y = y;
    this.radius = radius;
    this.c = c;
  }
  public void draw(Graphics g) {
    g.setColor(this.c); 
    g.fillOval(this.x - this.radius, 
               this.y - this.radius, 
               2 * this.radius, 
               2 * this.radius);  
    g.setColor(Color.RED); 
    g.drawOval(this.x - this.radius, 
               this.y - this.radius, 
               2 * this.radius, 
               2 * this.radius);  
  }
  public void move(int dx, int dy) {
    this.x += dx; 
    this.y += dy; 
  }
}
----------------------------------------------------------------------------------------------------