Java programs are made out of classes. 

Classes are containers. 

So far they contain static methods with: parameters, local variables, loops,
if statements, variables of types (primitive, objects such as arrays or even
array lists) and so on. 

(require 2htdp/image)
(require 2htdp/universe)

; A Point is a (make-point Number Number)
(define-struct point (x y))

; A Circle is a (make-circl Point Number)
(define-struct circl (center radius))

; A ManyCircl is one of:
;   -- empty

;   -- (cons Circle ManyCircl)

; A World is a ManyCircl 

; (big-bang initial
;           (to-draw ...)
;           (on-tick ...)
;           (on-mouse ...))

(define initial empty)

; render : World -> Image
; (define (render world)
;   (cond ((empty? world) ...)
;         (else (... (first world) ... (render (rest world)) ...))))
(define (render world)
  (cond ((empty? world) (empty-scene 400 400))
        (else (place-image (circle (circl-radius (first world)) "outline" "red")
                           (point-x (circl-center (first world)))
                           (point-y (circl-center (first world)))
                           (render (rest world))))))

(define sample-world (cons (make-circl (make-point 300 300) 30) 
                      (cons (make-circl (make-point 200 100) 80)
                       (cons (make-circl (make-point  50  50) 10) empty))))

; enlarge : circl -> circl
; increases the radius by 1 pixel 
(define (enlarge circl)
  (make-circl (circl-center circl) (add1 (circl-radius circl))))

; update : world -> world

(define (update world)
  (cond ((empty? world) world)
        (else (cons (enlarge (first world))
                    (update (rest world))))))

; meh : world x y event -> world

(define (meh world x y event)
  (cond ((mouse=? "button-down" event) 
         (cons (make-circl (make-point x y) 1)
               world))
        (else world)))

(big-bang sample-world
          (to-draw render)
          (on-tick update)
          (on-mouse meh))

How do I do this in Java? 

import java.util.Scanner; 

public class One {
  public static void main(String[] args) {
    Scanner s = new Scanner(System.in); 
    System.out.println( s ); 
  }
}

This prints:

Welcome to DrJava.  Working directory is C:\Users\dgerman\Desktop
> run One
java.util.Scanner[delimiters=\p{javaWhitespace}+][position=0][match valid=false][need input=false][source closed=false][skipped=false][group separator=\,][decimal separator=\.][positive prefix=][negative prefix=\Q-\E][positive suffix=][negative suffix=][NaN string=\Q?\E][infinity string=\Q?\E]


Now we try:

import javax.swing.JFrame; 

public class One {
  public static void main(String[] args) {
    JFrame f = new JFrame(); 
    System.out.println( f ); 
  }
}

This gives:

Welcome to DrJava.  Working directory is C:\Users\dgerman\Desktop
> run One
javax.swing.JFrame[frame0,0,0,0x0,invalid,hidden,layout=java.awt.BorderLayout,title=,resizable,normal,defaultCloseOperation=HIDE_ON_CLOSE,rootPane=javax.swing.JRootPane[,0,0,0x0,invalid,layout=javax.swing.JRootPane$RootLayout,alignmentX=0.0,alignmentY=0.0,border=,flags=16777673,maximumSize=,minimumSize=,preferredSize=],rootPaneCheckingEnabled=true]


So I end with this: 

import javax.swing.JFrame; 

public class One {
  public static void main(String[] args) {
    JFrame f = new JFrame(); 
    // System.out.println( f ); 
    f.setVisible(true); 
    f.setSize(400, 400); 
  }
}

Now we start learning how to create such things. 

Java programs are made of classes. 

Classes are containers. 

They contain members. 

Members can be: 

  (a) static (should be accessed through their class) 

  (b) non-static (instance, belong to objects once you create them)

Members are: 

  (a) variables

  (b) procedures 

Example: 

public class Two {
  public int x; // comes initialized with default value 
  public static int y; // comes initialized with default value 
  public int fun(int x, int y) {
    int answer;
    answer = x + y; 
    return answer;
  }
  public static int nuf(int x, int y) {
    int answer;
    answer = x + y; 
    return answer;
  }
}

import javax.swing.JFrame; 

public class One {
  public static void main(String[] args) {
    System.out.println( Two.y ); 
    Two.y = 4; 
    System.out.println( Two.y ); 
    Two a = new Two(); 
    System.out.println( a.x ); 
    a.x = 6;
    System.out.println( a.x ); 
    Two b = new Two(); 
    System.out.println( b.x ); 
    b.x = -2;
    System.out.println( b.x );     
    System.out.println( a.x ); 
  }
}

And now let's model with purpose. 

public class Student {
  
}

import javax.swing.JFrame; 

public class One {
  public static void main(String[] args) {
    Student tommy = new Student(); 
    Student jack, chiaHsuan; // two future students
    System.out.println( tommy ); 
    jack = new Student(); 
    chiaHsuan = new Student(); 
    System.out.println( jack ); 
    System.out.println( chiaHsuan ); 
    
  }
}

This prints:

Welcome to DrJava.  Working directory is C:\Users\dgerman\Desktop
> run One
Student@23c79d0e
Student@23c53936
Student@3e50ed21


http://www.cs.indiana.edu/classes/a202-dger/sum2010/zo.pdf

import javax.swing.JFrame; 

public class One {
  public static void main(String[] args) {
    Student tommy = new Student(); 
    Student jack, chiaHsuan; // two future students
    jack = new Student(); 
    chiaHsuan = new Student(); 
    tommy.name = "Tommy"; 
    jack.name = "Jack"; 
    chiaHsuan.name = "Chia-Hsuan"; 
    System.out.println( tommy.name );     
    System.out.println( jack.name );     
    System.out.println( chiaHsuan.name );     
  }
}

import javax.swing.JFrame; 

public class One {
  public static void main(String[] args) {
    Student tommy = new Student(); 
    Student jack, chiaHsuan; // two future students
    jack = new Student(); 
    chiaHsuan = new Student(); 
    tommy.name = "Tommy"; 
    jack.name = "Jack"; 
    chiaHsuan.name = "Chia-Hsuan"; 
    System.out.println( tommy.talk() );     
    System.out.println( jack.talk() );     
    System.out.println( chiaHsuan.talk() );     
  }
}

class Point {
  int x, y;
  
}

class Circle {
  Point center;
  int radius; 
  double area() {
    return Math.PI * radius * radius; 
  }
}

--