2:12 PM 4/12/2015

Ben B, David L, Peng C, Yaxin T, Thomas A

http://docs.oracle.com/javase/tutorial/uiswing/

http://zetcode.com/tutorials/javaswingtutorial/

http://zetcode.com/tutorials/javagamestutorial/

http://cs.nyu.edu/~yap/classes/visual/03s/lect/l7/

http://www.tutorialspoint.com/swing/

https://www3.ntu.edu.sg/home/ehchua/programming/java/J4a_GUI.html

http://www.tutorialspoint.com/javaexamples/java_simple_gui.htm

Peng: Happy to be here.

David: Homework Nine. 

Ben: I want to learn something!

Yaxin: Homework Seven. 

Thomas: Homework Ten.

http://www.greenfoot.org/scenarios/335

Welcome to DrJava.  Working directory is C:\Users\dgerman
> 1 + 1
2
> import javax.swing.*;
> int b = 3 + 4;
> b
7
> JFrame a = new JFrame();
> a
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]
> a.setVisible(true)
> a.setWidth(100);
Static Error: No method in JFrame has name 'setWidth'
> a.setSize(100, a.getHeight());
> a.setSize(80, a.getHeight());
> a.setSize(20, a.getHeight());
> a.setSize(120, a.getHeight());
> a.setSize(420, a.getHeight());
> a.setSize(380, a.getHeight());
>

// run this as follows: java One 300 200
public class One {
  public static void main(String[] args) {
    JFrame a = new JFrame();
    a.setSize( Integer.parseInt(args[0]), Integer.parseInt(args[1]) ); 
    a.setVisible(true); 
  } 
}

How do you do Homework Seven?

http://www.greenfoot.org

http://www.greenfoot.org/download

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

Download and unzip (extract). 

http://www.greenfoot.org/door

http://www.greenfoot.org/book

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

Download and unzip (extract) the book scenarios. 

Start Greenfoot and locate the game scenario.

Play the game, share, webpage, export (browse). 

I created yaxin-marbles on the desktop. 

I use WinSCP to connect to silo. 

I create a new empty context in webapps

I also modified my Tomcat home page

[yaxtang@silo ROOT]$ pwd
/u/yaxtang/apache-tomcat-7.0.35/webapps/ROOT
[yaxtang@silo ROOT]$ cat index.html
I think Brad Stevens is the Hemingway of NBA. Just look at him:

<blockquote><img src="https://collegesportstown.files.wordpress.com/2013/07/bradstevens.jpg"></blockquote>

I am Yaxin Tang <img src="http://www.cs.indiana.edu/~dgerman/spr2015/images/yaxtang.jpg"> and I approved this message. (Go Hillary!) <p>

I also finished Homework Seven (here's <a href="hwSeven/yaxin-marbles/marbles.html">Marbles</a>).


[yaxtang@silo ROOT]$

Here's what I created with Greenfoot:

[yaxtang@silo webapps]$ pwd
/u/yaxtang/apache-tomcat-7.0.35/webapps
[yaxtang@silo webapps]$ ls -l
total 36
drwx------  3 yaxtang students 4096 Feb 19 18:57 chat
drwx------ 13 yaxtang students 4096 Feb 19 16:55 docs
drwx------  6 yaxtang students 4096 Feb 19 16:55 examples
drwx------  5 yaxtang students 4096 Feb 19 16:55 host-manager
drwx------  3 yaxtang students 4096 Apr 12 14:59 hwSeven
drwx------  3 yaxtang students 4096 Feb 19 18:38 iceblox
drwx------  5 yaxtang students 4096 Feb 19 16:55 manager
drwx------  3 yaxtang students 4096 Feb 19 18:12 ROOT
drwx------  3 yaxtang students 4096 Mar 26 17:30 squash
[yaxtang@silo webapps]$ du -a hwSeven/
592     hwSeven/yaxin-marbles/marbles.jar
4       hwSeven/yaxin-marbles/marbles.html
140     hwSeven/yaxin-marbles/jl1.0.1.jar
740     hwSeven/yaxin-marbles
744     hwSeven/
[yaxtang@silo webapps]$

I then add the URL and give permissions, stop and start the browser and

http://silo.cs.indiana.edu:13731/hwSeven/yaxin-marbles/marbles.html


class LabTwelve {
  JTextField a, b, c;
  LabTwelve() {
    ... // sets the GUI elements, like a, b, c and so on 
  }
  public void actionPerformed(ActionEvent e) {
    c.setText("" + Double.parseDouble(a.getText()) * Double.parseDouble(b.getText()));
  } 
  public static void main(String[] args) {
    ... // creates the JFrame etc. 
  }
}

Now a bit of discussion about stage two:

  import java.awt.event.*;
  import javax.swing.*;
  
  class Two extends JFrame implements ActionListener, KeyListener {
    public void keyPressed (KeyEvent e) { }
    public void keyReleased(KeyEvent e) { }
|   public void keyTyped   (KeyEvent e) {
|     System.out.println(" kieo;wry34rt ");
|     totalLabel.setText("");
|    }
    public void actionPerformed(ActionEvent e) {
      // System.out.println( e );
      totalLabel.setText( "" + Math.sqrt( Double.parseDouble( numberTextField.getText() )));
    }
    JTextField numberTextField;
    JLabel numberLabel, totalLabel;
    Two() {
      JButton action;
      JPanel panel = new JPanel();
      panel.setLayout( null );
      numberLabel = new JLabel("Number: ");
      numberLabel.setBounds(30, 30, 120, 20);
      panel.add(numberLabel);
      numberTextField = new JTextField();
      //  numberTextField.setPreferredSize( new Dimension(60,20));
      numberTextField.setBounds(70, 70, 60, 20);
|     numberTextField.addKeyListener( this );
      panel.add(numberTextField);
      action = new JButton( "Calculate" );
      action.setBounds(100, 100, 100, 20);
      panel.add( action );
      action.addActionListener( this );
      totalLabel = new JLabel( "..." );
      totalLabel.setBounds(150, 150, 160, 20);
      panel.add(totalLabel);
      this.add(panel);
      this.setSize(400, 200);
      this.setVisible(true);
      this.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
    }
    public static void main(String[] args) {
|     Two frame = new Two();
    }
  }


The output in Lab Twelve:

      totalResultJTextField = new JTextField(); 
      totalResultJTextField.setBounds( 244, 16, 186, 21 );
      totalResultJTextField.setHorizontalAlignment( JTextField.RIGHT );
      totalResultJTextField.setEditable( false ); 


http://www.cs.indiana.edu/classes/c212/fall2010/notes/ouch.jpg

http://docs.oracle.com/javase/7/docs/api/java/awt/event/KeyListener.html

Hree's the example:

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

public class Broker implements KeyListener {
  JLabel label;
  public Broker(JLabel d) {
    this.label = d;  
  }
  public void keyPressed(KeyEvent e) { } 
  public void keyReleased(KeyEvent e) { } 
  public void keyTyped(KeyEvent e) { 
    System.out.println( e.getKeyChar() ); 
    this.label.setText( "" + e.getKeyChar() ); 
  } 
}

import javax.swing.*;
import java.awt.*;
class Thomas {
  public static void main(String[] args) {
    JFrame a = new JFrame(); 
    JPanel b = new JPanel();     
    JLabel d = new JLabel("Output."); 
    JTextField c = new JTextField(); 
    c.addKeyListener(new Broker(d)); 
    c.setPreferredSize( new Dimension(60,20));    
    b.add(c);
    b.add(d);
    a.getContentPane().add(b); 
    a.setVisible(true); 
    a.setSize(400, 400); 
  }
}

http://docs.oracle.com/javase/7/docs/api/java/awt/event/KeyEvent.html

http://silo.cs.indiana.edu:8346/04142012/007.html

http://www.cs.indiana.edu/classes/c212/fall2010/notes/ouch.jpg

Here's the Windows terminal: 

Microsoft Windows [Version 6.3.9600]
(c) 2013 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 labTwo01.jar
 Volume in drive C is OSDisk
 Volume Serial Number is 9033-8CDA

 Directory of C:\Users\dgerman\Desktop

04/12/2015  03:30 PM             2,297 labTwo01.jar
               1 File(s)          2,297 bytes
               0 Dir(s)  318,523,224,064 bytes free

C:\Users\dgerman\Desktop>javac
'javac' is not recognized as an internal or external command,
operable program or batch file.

C:\Users\dgerman\Desktop>PATH=%PATH%;"C:\Program Files\Java\jdk1.8.0_05\bin"

C:\Users\dgerman\Desktop>javac
Usage: javac <options> <source files>
where possible options include:
  -g                         Generate all debugging info
  -g:none                    Generate no debugging info
  -g:{lines,vars,source}     Generate only some debugging info
  -nowarn                    Generate no warnings
  -verbose                   Output messages about what the compiler is doing
  -deprecation               Output source locations where deprecated APIs are u
sed
  -classpath <path>          Specify where to find user class files and annotati
on processors
  -cp <path>                 Specify where to find user class files and annotati
on processors
  -sourcepath <path>         Specify where to find input source files
  -bootclasspath <path>      Override location of bootstrap class files
  -extdirs <dirs>            Override location of installed extensions
  -endorseddirs <dirs>       Override location of endorsed standards path
  -proc:{none,only}          Control whether annotation processing and/or compil
ation is done.
  -processor <class1>[,<class2>,<class3>...] Names of the annotation processors
to run; bypasses default discovery process
  -processorpath <path>      Specify where to find annotation processors
  -parameters                Generate metadata for reflection on method paramete
rs
  -d <directory>             Specify where to place generated class files
  -s <directory>             Specify where to place generated source files
  -h <directory>             Specify where to place generated native header file
s
  -implicit:{none,class}     Specify whether or not to generate class files for
implicitly referenced files
  -encoding <encoding>       Specify character encoding used by source files
  -source <release>          Provide source compatibility with specified release

  -target <release>          Generate class files for specific VM version
  -profile <profile>         Check that API used is available in the specified p
rofile
  -version                   Version information
  -help                      Print a synopsis of standard options
  -Akey[=value]              Options to pass to annotation processors
  -X                         Print a synopsis of nonstandard options
  -J<flag>                   Pass <flag> directly to the runtime system
  -Werror                    Terminate compilation if warnings occur
  @<filename>                Read options and filenames from file


C:\Users\dgerman\Desktop>java -classpath labTwo01.jar Inventory

C:\Users\dgerman\Desktop>java -classpath labTwo02.jar Inventory

C:\Users\dgerman\Desktop>java -classpath labTwelve.jar TypingApplication

C:\Users\dgerman\Desktop>

--