Chen asked about Homework Seven

https://www.cs.indiana.edu/classes/c212-dgerman/spr2015/griffin/c.pdf

http://www.greenfoot.org/door

http://www.greenfoot.org/download

http://bluej.org/download/files/bluej314-greenfoot241-standalone.zip

http://www.greenfoot.org/book/

http://www.greenfoot.org/book/material/book-scenarios.zip

1. Open Greenfoot

2. Open scenario

3. Publish, WinSCP or ftp to Tomcat

4. Load in browser

Any questions? 

Exam next week. Monday let's practice. 

Today, tomorrow, this weekend: I will send e-mail individually. 

Homework Eight, posted. Retake midterm with it.

I need to create a lot of boxes in OnCourse. 

Homework Nine has three parts. 

Homework Ten is setting up the third exam. 

Lab Twelve posted deals with GUIs and some more types of listeners. 

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

1. Should we discuss Eyes? If so how many should we create? One? Two? Six? Eight? Twelve? 

2. If more than one, should the Eyes be identical or have different dimensions? 

3. How do we make the math work? 

Haleigh, Erin, Ben, Michael, Brian, Danielle, Connor, Taylor, Mahamat, Chen, Kohki, Daniel, Minh
Nick Palmer, Phoebe, Brandon, Joe, Nick Palumbo, Seong In Park, Griffin, Shane Bielefeld, Shikun

Yes. Eight. No. Let's see ... 

http://www.disneymania.com.br/wp-content/uploads/2010/06/toy-story-aliens-disneymania-widescreen-1.jpg

import java.awt.*; 

public class Eye {
  int x, y, 
      xt, yt; // initially zero 
  public Eye(int x, int y, int R, int r) {
    this.x = x;
    this.y = y;
    this.xt = x; 
    this.yt = y; 
    this.R = R;
    this.r = r; 
  }
  public void setTarget(int x, int y) {
    this.xt = x;
    this.yt = y; 
  }
  int 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);
    Color c = new Color(0.37f, 0.97f, 0.51f); 
    g.setColor(c);
    double dx = this.x - this.xt;
    double dy = this.y - this.yt;
    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); 
    g.setColor(Color.BLACK); 
  }
}

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

public class Griffin extends JComponent implements MouseMotionListener {
  Eye[] eyes = new Eye[16]; 
  public Griffin() {
    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() * 20 + 20), 
                             (int) (Math.random() * 4 + 8) ); 
  }
  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 javax.swing.*;
import java.awt.*; 

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

There's a Homework Help Session every Sunday 2-4pm. 

--