I have to update links in OnCourse 

Homework Eight

Homework Nine

Homework Ten

Third Exam Lab

Lab Twelve

Submit files as .java attachments (ancillary documents as .txt)

I will e-mail you over the next three days asking:

(a) if you're ready for the new exam

(b) if your grades are up to date and you're happy

(c) if you want to come pick up older exams discuss and adjust grades

(d) how you're doing with the various assignments

For Lab Twelve check the notes posted for today. 

Also: http://silo.cs.indiana.edu:8346/04142012/001.html

https://docs.oracle.com/javase/tutorial/

https://docs.oracle.com/javase/tutorial/reallybigindex.html

https://docs.oracle.com/javase/tutorial/uiswing/index.html

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

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

I'd like you to be able to implement an eye or more easily. 

1. Should we program one, two or more eyes? How many eyes? 

2. If more than one, should they have different sizes?

3. How do we use the math to make the eye behave as it should? 

Chris N, Zach S, Thomas A, Clayton, Daniel O, Laura, Noah, 
Samy R, Nick F, Rodrigo V, Jake d, Anna, Jeremy B, Josh P, 
Alex D. Jay K, Santiago, Hao, Jordan, Andrew D, Pong, David L,
Andrzej, Dimas, Danny N, Xinning W, Adam K, Seth W, Jacob C, 
Rishab S, Alex T, Donovan M, Zhengyu, Yangjun, Anthony, Austin M,
Caleb G, Ethan Y, Troy S, Shichao, Angely, Yingzhen Q, Joel P, 
Quintin L, Cheng C, Morgan N, Brad V, Scott M, Nikita M, Megan M, 
Jordan G, Brittany H, Sam Berron, Yongtao C(*)

Let's define an array of eyes, of random sizes and positions. 

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

public class Program extends JFrame {
  public Program() {
    Container c = this.getContentPane();
    this.add( new Screen() ); 
    this.setVisible(true); 
    this.setSize(400, 400);
    // this.setDefaultCloseOperation( EXIT_ON_CLOSE ); 
  }
  public static void main(String[] args) {
    JFrame f = new Program();  
  }
}

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

public class Screen extends JComponent implements MouseMotionListener {
  Eye[] eyes = new Eye[30];
  public Screen() {
    this.addMouseMotionListener(this);  
    for (int i = 0; i < this.eyes.length; i++) {
      this.eyes[i] = new Eye( (int) (Math.random() * 400), 
                              (int) (Math.random() * 400), 
                              (int) (Math.random() * 10 + 30), 
                              (int) (Math.random() * 5 + 5)
        );  
    }
  }
  public void mouseMoved(MouseEvent e) { 
    int x = e.getX(), y = e.getY(); 
    for (Eye eye : this.eyes) 
      eye.setTarget(x, y); 
    this.repaint(); 
    
  }
  public void mouseDragged(MouseEvent e) { }
  public void paintComponent(Graphics g) {
    for (Eye e : this.eyes) {
      e.draw(g);  
    }
  }
  
}

import java.awt.*; 
  
public class Eye {
  int x, y;
  int xt, yt; // initially what? 
  int R, r;
  public void setTarget(int x, int y) {
    this.xt = x;
    this.yt = y; 
  }
  public Eye(int x, int y, int R, int r) {
    this.x = x; 
    this.y = y;
    this.R = R;
    this.r = r;
  }
  public void draw(Graphics g) {
    // g.drawString("Eye", this.x, this.y); 
    // g.drawLine(this.x, this.y, this.xt, this.yt); 
    g.drawOval(this.x - R, this.y - R, 2 * R, 2 *R); 
    int dx = this.xt - this.x; 
    int dy = this.yt - this.y;     
    double distance = Math.sqrt( dx * dx + dy * dy ); 
    double p = (R-r) / distance; 
    int x = (int) (this.x + p * (this.xt - this.x)); 
    int y = (int) (this.y + p * (this.yt - this.y));     
    if (distance < R-r) {
      x = this.xt;
      y = this.yt; 
    } 
    g.fillOval(x - r, y - r, 2 * r, 2 * r); 
  }
}

--