Howdy. 

Evan, Jing, Rob, Noor, Jack, Tommy, Alex, Andrew, 

Kongchen, Shengyu, Chia-Hsuan, Yi, Chenyang, Jun, Troy 

http://silo.cs.indiana.edu:8346/c212/spr2015/tetris.rkt

How do I draw Graphics?

https://docs.oracle.com/javase/tutorial/uiswing/components/toplevel.html

import javax.swing.*;

// http://docs.oracle.com/javase/8/docs/api/javax/swing/JFrame.html

public class Bracket extends JFrame {
  public Bracket() {
    super(); 
    this.setVisible(true); 
    this.setSize(400, 400);
  }
  public static void main(String[] args) {
    Bracket b = new Bracket();
    b.add( new Screen() ); 
  }
}

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

// http://docs.oracle.com/javase/8/docs/api/javax/swing/JComponent.html
// http://docs.oracle.com/javase/8/docs/api/java/awt/Graphics.html

public class Screen extends JComponent {
  public void paintComponent(Graphics g) {
    g.setColor(Color.YELLOW); 
    g.fillOval(90, 190, 60, 60); 
    g.setColor(Color.BLUE); 
    g.drawOval(80, 200, 60, 60); 
    g.setColor(Color.BLACK); 
  }
}

Last time we were able to note that the mouse was moving. 

import javax.swing.*;

// http://docs.oracle.com/javase/8/docs/api/javax/swing/JFrame.html

public class Bracket extends JFrame {
  public Bracket() {
    super(); 
    this.setVisible(true); 
    this.setSize(400, 400);
  }
  public static void main(String[] args) {
    Bracket b = new Bracket();
    b.add( new Screen() ); 
  }
}

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

// http://docs.oracle.com/javase/8/docs/api/javax/swing/JComponent.html
// http://docs.oracle.com/javase/8/docs/api/java/awt/Graphics.html

public class Screen extends JComponent implements MouseMotionListener {
  public Screen() {
    super(); 
    this.addMouseMotionListener( this ); 
    // http://docs.oracle.com/javase/8/docs/api/java/awt/event/MouseListener.html
  }
// http://docs.oracle.com/javase/8/docs/api/java/awt/event/MouseMotionListener.html
  public void mouseMoved(MouseEvent e) { }
  public void mouseDragged(MouseEvent e) { 
    int x = e.getX(), y = e.getY(); 
    System.out.println( "Mouse dragged at (" + x + ", " + y + ")" ); 
  }
  public void paintComponent(Graphics g) {
    g.setColor(Color.YELLOW); 
    g.fillOval(90, 190, 60, 60); 
    g.setColor(Color.BLUE); 
    g.drawOval(80, 200, 60, 60); 
    g.setColor(Color.BLACK); 
  }
}

So how do I draw the position of the mouse (as a pair (x, y)) on the Screen? 

import javax.swing.*;

public class Bracket extends JFrame {
  public Bracket() {
    super(); 
    this.setVisible(true); 
    this.setSize(400, 400);
  }
  public static void main(String[] args) {
    Bracket b = new Bracket();
    b.add( new Screen() ); 
  }
}

Completely unchanged. 

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

public class Screen extends JComponent implements MouseMotionListener {
  public Screen() {
    super(); 
    this.addMouseMotionListener( this ); 
  }
  public void mouseMoved(MouseEvent e) { }
  public void mouseDragged(MouseEvent e) { 
    int x = e.getX(), y = e.getY(); 
    System.out.println( "Mouse dragged at (" + x + ", " + y + ")" ); 
    // http://docs.oracle.com/javase/8/docs/api/javax/swing/JComponent.html#getGraphics--
    // Graphics alex = this.getGraphics(); 
    // alex.drawString("I am here", x, y);     
    this.x = x; 
    this.y = y; 
    this.repaint();
  }
  private int x, y; 
  public void paintComponent(Graphics g) {
    System.out.println("I am painting."); 
    g.drawString("I'm addicted to placebos.",180, 50);
    g.setColor(Color.YELLOW); 
    g.fillOval(90, 190, 60, 60); 
    g.setColor(Color.BLUE); 
    g.drawOval(80, 200, 60, 60); 
    g.setColor(Color.BLACK); 
    // becase of the MVC pattern 
    g.drawString("(" + this.x + ", " + y + ")", x, y);
  }
}

Now here's what you need to do before you start the project. 

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

class BigBang extends JComponent implements KeyListener, ActionListener, MouseListener {
  Timer timer; 
  World world; 
  BigBang(int delay, World world) {
    timer = new Timer(delay, this); 
    this.world = world;
  } 
  public void start() {
    timer.start();  
  }
  BigBang(World world) {
    this(1000, world);  
  }
  public void paintComponent(Graphics g) {
    world.draw(g);  
  }
  public void actionPerformed(ActionEvent e) {
    world.update(); 
    if (world.hasEnded())
      timer.stop(); 
    this.repaint(); 
  }
  public void keyPressed(KeyEvent e) { 
    world.keyPressed(e); 
    this.repaint(); 
  } 
  public void keyTyped(KeyEvent e) { } 
  public void keyReleased(KeyEvent e) { } 

  public void mousePressed(MouseEvent e) { 
    world.mousePressed(e); 
    this.repaint(); 
  } 
  public void mouseReleased(MouseEvent e) { } 
  public void mouseClicked(MouseEvent e) { } 
  public void mouseEntered(MouseEvent e) { } 
  public void mouseExited(MouseEvent e) { } 

}