Welcome back!

You have seen Greenfoot. 

You have seen BlueJ. 

You have seen DrJava. 

Let's look at a game written in 1996. 

The steps are:

(a) get the picture

(b) get the code and compile it

(c) create index.html and run appletviewer on it

Don't forget to set the PATH:

PATH=%PATH%;"C:\Program Files\Java\jdk1.6.0_33\bin"

That will give you javac, java, appletviewer. 

Next we develop the following program: 

import javax.swing.JFrame; 
import javax.swing.Timer; 
import javax.swing.JComponent; 
import java.awt.*; 
import java.awt.event.ActionListener; 
import java.awt.event.ActionEvent; 
import java.util.ArrayList; 

class TV extends JFrame {
  TV() {
    Screen screen = new Screen(); 
    Timer timer = new Timer(500, screen); 
    timer.start(); 
    this.add( screen ); 
    this.setVisible(true); 
    this.setSize(200, 200); 
    this.setDefaultCloseOperation( 3 ); 
  }
}

class Screen extends JComponent implements ActionListener {
   ArrayList<Circle> circles; 
   Screen() {
     this.circles = new ArrayList<Circle>(); 
     for (int i = 0; i < 10; i = i + 1) {
       this.circles.add( new Circle( (int) ( 200 * Math.random() ), 
                                     (int) ( 200 * Math.random() ),
                                     (int) ( 10 + 20 * Math.random() ) )

                       ); 
     } 
   }
   public void actionPerformed(ActionEvent e) {
     System.out.println("Tick tick..."); 
     this.time = this.time + 1;
     this.repaint(); 
   } 
   int time = 0; 
   public void paintComponent(Graphics g) {
     g.drawString( " The time is now:  " + time , 50, 80 ); 
     for (Circle c : this.circles) 
       c.draw(g); 
   }
}

class Program {
  public static void main(String[] args) {
    JFrame a = new TV(); 
  } 
}

class Circle {
  int x, y, radius;
  Circle(int x, int y, int radius) {
    this.x = x;
    this.y = y; 

    this.radius = radius;
  }
  void draw(Graphics g) {
    g.setColor(Color.YELLOW); 
    g.fillOval(this.x, this.y,this.radius * 2, this.radius * 2); 
  }
}

http://docs.oracle.com/javase/7/docs/api/javax/swing/Timer.html

http://docs.oracle.com/javase/6/docs/api/javax/swing/Timer.html

http://docs.oracle.com/javase/6/docs/api/javax/swing/JComponent.html

http://docs.oracle.com/javase/tutorial/uiswing/components/jcomponent.html

http://docs.oracle.com/javase/tutorial/uiswing/misc/timer.html

http://docs.oracle.com/javase/6/docs/api/java/awt/event/ActionListener.html

Here's the program we wrote in the second class: 

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

class Adam {
  public static void main(String[] args) {
    JFrame a = new One( Integer.parseInt( args[0] )); 
  }
}

class One extends JFrame {
  One(int n) {
    Two screen = new Two(n); 
    this.add( screen ); 
    this.setVisible(true); 
    this.setSize(400, 400); 
    this.setDefaultCloseOperation( EXIT_ON_CLOSE ); 
  } 
}

class Two extends JComponent {
  ArrayList<Circle> circles;
  Two(int howMany) {
    this.circles = new ArrayList<Circle>(); 
    for (int i = 0; i < howMany; i = i + 1) {
      this.circles.add( new Circle(new Point( (int) (Math.random() * 100 + 50), 
                                              (int) (Math.random() * 100 + 50)), 
                                   (int) (Math.random() * 20 + 10) ,
                                   new Color( (float) Math.random() , 
                                              (float) Math.random() , 
                                              (float) Math.random() ) )
                      ); 
    }     
  }  
  public void paintComponent(Graphics g) {
    // g.drawOval(50, 50, 100, 100); 
    for (Circle c : this.circles) 
      c.draw(g); 
  } 
}

class Circle {
  Point center;
  int radius;
  Color color;
  Circle(Point center, int radius, Color color) {
    this.center = center; 
    this.radius = radius; 
    this.color = color;
  }
  void draw(Graphics g) {
    g.setColor( this.color );// new Color( 1.0f, 1.0f, 0.0f )); 
    g.fillOval(this.center.x, this.center.y, this.radius * 2, this.radius * 2); 
    g.setColor(Color.BLACK); 
    g.drawOval(this.center.x, this.center.y, this.radius * 2, this.radius * 2);
  } 
}

class Point {
  int x, y; 
  Point(int x, int y) {
    this.x = x;
    this.y = y; 
  }
}

--