Questions on the third exam:

1. Write simplest program that reports mouse movement (MouseMotionListener). 

2. Write simplest program that reports mouse buttons being clicked (MouseListener). 

3. Write simplest program that keeps time. 

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

public class Three implements ActionListener {
  public static void main(String[] args) {
    Three three = new Three();
    Timer timer = new Timer(1000, three); 
    timer.start(); 
  }
  int count = 0; 
  public void actionPerformed(ActionEvent e) {
    this.count += 1; 
    System.out.println( this.count ); 
  }
}

The simplest -- so nothing unnecessary should be included. 

4. Write simplest program that shows how to sort objects using Comparable. 

5. Write simplest program that shows how to sort objects using Comparator. 

6. Write simplest program that shows how to use Exceptions. 

7. Write simplest program that processes and responds to keyboard events. 

8. Write simplest program that creates and shows on the screen a few circles of different colors. 

https://www.cs.indiana.edu/classes/c212-dgerman/spr2015/bgbng_files/image002.jpg

import javax.swing.JFrame; 
import javax.swing.JComponent; 
import java.awt.Graphics;
import java.util.ArrayList; 
import java.awt.Color;

public class Eight extends JComponent {
  ArrayList<Circle> circles = new ArrayList<Circle>(); 
  public Eight() {
    for (int i = 0; i < 30; i++) {
      this.circles.add(new Circle((int)(Math.random()*400), 
                                  (int)(Math.random()*400), 
                                  (int)(Math.random() * 10 + 30),
                                  new Color((float)Math.random(), 
                                            (float)Math.random(), 
                                            (float)Math.random())));  
    }
  }
  public void paintComponent(Graphics g) {
    g.drawOval(40, 40, 100, 100); // likewise, not needed, just a sanity check
    for (Circle c : this.circles)
      c.draw(g); 
    System.out.println("I am being called." + this.circles); // for illustration only 
  }
  public static void main(String[] args) {
    JFrame a = new JFrame(); 
    a.add( new Eight() ); 
    a.setSize(400, 400); 
    a.setVisible(true); 
  }
}

import java.awt.Color; 
import java.awt.Graphics; 

public class Circle {
  int x, y; 
  int radius;
  Color c;
  public String toString() {
    return this.c + " circle (" + this.x + ", " + this.y + ") with radius + " + this.radius;  
  } // I needed this for debugging 
  public Circle(int x, int y, int r, Color c) {
    this.x = x; 
    this.y = y; 
    this.radius = r;
    this.c = c; 
  }
  public void draw(Graphics g) {
    g.setColor(this.c); 
    g.fillOval(this.x - this.radius, 
               this.y - this.radius, 
               this.radius * 2, 
               this.radius * 2);  
    g.setColor(Color.BLACK);     
    g.drawOval(this.x - this.radius, 
               this.y - this.radius, 
               this.radius * 2, 
               this.radius * 2);  
    
  }
}

9. Write simplest program with a JButton, JTextField and JLabel. 

--

Possible stages for the project:

Stage One: BigBang, with World and initial state of the world is shown. 

Stage Two: Shoot circles and they bounce off the walls, but stick to the ceiling. 

Stage Three: Finish game (upon landing some of the ceiling may vanish).

Sample final: 

(a) add an ending to the game

(b) keep score

(c) adding a shadow like in the sample project (Tetris) 

(d) modify game so isolated groups of circles can be left behind