Lab 15, 16, reading the book, preparing for the final tomorrow. 

Exam is 30 random questions from the 156+ posted in the study guide. 

import javax.swing.*; 

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

Section 2.9.1 is fine. 

import javax.swing.*; 

public class Two extends JFrame {
  public Two() {
    this.setSize(300, 400); 
    this.setVisible(true);     
  }
  public static void main(String[] args) {
    Two a = new Two();  
  }
}

I have created a JFrame this time. 

I could have had a JFrame and rely on composition. 

http://sportycious.com/wp-content/uploads/2014/10/Some-of-the-Interesting-Facts-about-Hang-Gliding.jpg

The picture above demonstrates the equivalence of composition and inheritance. 

http://www.flyingsquirrelbar.com/images/real-flying-squirrel.png

There is a difference between composition and inheritance but not that big.

import javax.swing.*; 

public class Two extends JFrame {
  public Two() {
    this.add( new Circle(150, 280, "Dan") ); 
    this.add( new Circle( 50,  80, "Adrian") ); 
    this.setSize(300, 400); 
    this.setVisible(true);     
  }
  public static void main(String[] args) {
    Two a = new Two();  
  }
}

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

public class Circle extends JComponent {
  String name;
  int x, y; 
  public Circle(int x, int y, String name) {
    this.x = x; 
    this.y = y; 
    this.name = name; 
  }
  int count = 0; 
  public void paintComponent(Graphics g) {
    System.out.println( this.count++ ); 
    g.drawString(this.name, this.x, this.y);     
  }
}

I thought I'd get both names but apparently not. 

https://docs.oracle.com/javase/tutorial/2d/index.html

I now am able to draw my first conclusion: 

  (a) get a JComponent
  (b) attach to a JFrame
  (c) design a World (with Circles, etc)
  (d) teach your JComponent to render the World

However there must be a way to actually show two components at the same time. 

--

import javax.swing.*; 

public class Two extends JFrame {
  public Two() {
    this.add( new Circle(150, 280, "Dan") ); 
    this.add( new Circle( 50,  80, "Adrian") ); 
    this.setSize(300, 400); 
    this.setVisible(true);     
  }
  public static void main(String[] args) {
    Two a = new Two();  
  }
}

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

public class Circle extends JComponent {
  String name;
  int x, y; 
  public Circle(int x, int y, String name) {
    this.x = x; 
    this.y = y; 
    this.name = name; 
  }
  int count = 0; 
  public void paintComponent(Graphics g) {
    System.out.println( this.count++ ); 
    g.drawString(this.name, this.x, this.y);     
  }
}

How can I see both "circles" here? 

Misato   Daniel R Katherine Jillian Patrick Daniel Nelson Tao 
Iris     Kefei    Yibo      Khalea  Elise   Keiland       Noah 
Nicholas Daniel C John      Jiang   Bihan   Stuart        Justin
Ryan     Taylor   dgerman 

Next I looked at Iceblox:

Microsoft Windows [Version 10.0.10586]
(c) 2015 Microsoft Corporation. All rights reserved.

C:\WINDOWS\system32>cd \

C:\>cd Users

C:\Users>cd dgerman

C:\Users\dgerman>cd Desktop

C:\Users\dgerman\Desktop>dir Iceblox.java
 Volume in drive C is OSDisk
 Volume Serial Number is FC4B-5BA2

 Directory of C:\Users\dgerman\Desktop

07/26/2017  12:33 PM            17,926 Iceblox.java
               1 File(s)         17,926 bytes
               0 Dir(s)  346,653,175,808 bytes free

C:\Users\dgerman\Desktop>javac Iceblox.java
Note: Iceblox.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.

C:\Users\dgerman\Desktop>dir
 Volume in drive C is OSDisk
 Volume Serial Number is FC4B-5BA2

 Directory of C:\Users\dgerman\Desktop

07/26/2017  12:42 PM    <DIR>          .
07/26/2017  12:42 PM    <DIR>          ..
07/26/2017  12:32 PM               827 Circle.class
07/26/2017  12:32 PM               392 Circle.java
07/26/2017  12:08 PM               145 Circle.java~
07/26/2017  12:42 PM            14,798 Iceblox.class
07/26/2017  12:33 PM             9,719 iceblox.gif
07/26/2017  12:33 PM               191 iceblox.html
07/26/2017  12:33 PM            17,926 Iceblox.java
07/26/2017  12:32 PM               511 One.class
07/26/2017  11:54 AM               215 One.java
07/26/2017  11:53 AM               159 One.java~
07/26/2017  12:32 PM               646 Two.class
07/26/2017  12:32 PM               320 Two.java
07/26/2017  11:58 AM               223 Two.java~
              13 File(s)         46,072 bytes
               2 Dir(s)  346,653,052,928 bytes free

C:\Users\dgerman\Desktop>type iceblox.html
<html>
  <head><title>IceBlox - by Karl Hornell (Apr. 8, 1996)</title></head>
  <body bgcolor=white>

    <applet code="Iceblox.class" width=400 height=400>

    </applet>

  </body>
</html>

C:\Users\dgerman\Desktop>appletviewer iceblox.html
Warning: Can't read AppletViewer properties file: C:\Users\dgerman\.hotjava\properties Using defaults.

C:\Users\dgerman\Desktop>

--

See you in lab.