Java1 Intro

download Java1 Intro

of 17

Transcript of Java1 Intro

  • 8/6/2019 Java1 Intro

    1/17

    Developing User Interfaces

    (DUI)

    Chris North

    cs3724: HCI

  • 8/6/2019 Java1 Intro

    2/17

    GUI Development: Goals

    1. Learn generalGUI programming concepts GUI components

    Layout

    Event-based programming

    Graphics

    Animation

    2. Learn Java Swing

    Layout managers

    Listerners

    2D graphics Threads

    Then: can learn other languages quickly VB, C#, Xwin, Java 49

  • 8/6/2019 Java1 Intro

    3/17

    Intro to Java

  • 8/6/2019 Java1 Intro

    4/17

    Why Java?

  • 8/6/2019 Java1 Intro

    5/17

    Java materials

    Java 2 = sdk 1.2 or better

    http://java.sun.com/j2se/

    Documentation:

    http://java.sun.com/docs/

    Tutorials, reference, API

    Borland JBuilder 6 http://www.borland.com/jbuilder/personal/

    Free! Cross between VB and VC++

  • 8/6/2019 Java1 Intro

    6/17

    Java differences Basic statements identical to C++

    Object-oriented only! No .h files

    main() is inside a class

    No global variables

    No pointers (object references only)

    No delete: automatic garbage collection

    Single inheritance only, interfaces

    Applet/application

    GUI: AWT, Swing

    Packaging Error Handling, exceptions (try, catch)

    E.g. Array bounds checking

    Security

    Components: beans

  • 8/6/2019 Java1 Intro

    7/17

    Java compiling

    Code:

    hello.java (text file)

    Compile:javac hello.java

    Creates: hello.class (byte code)

    Run:

    java hello Java virtual machine, interpets/compiles (machine code)

    Packaging: jar

    Or use JBuilder, like VC++

  • 8/6/2019 Java1 Intro

    8/17

    Java Applications

    Run from command line

    hello.java:class hello {

    public static void main(String[] args){System.out.println(Hello World!);

    }

    }

    javac hello.java

    java hello

    Hello World!

  • 8/6/2019 Java1 Intro

    9/17

    Typically create objects

    hello.java:class hello {

    public static void main(String[] args){

    // Create and use objects

    hello h = new hello();

    }

    public hello(){ // Constructor

    }

    }

  • 8/6/2019 Java1 Intro

    10/17

    Many Classes

    Compile each separately Can be main( ) in any/all classes

    hello.java:class hello {

    goodbye g;

    public static voidmain(String[] args){

    }

    goodbye.java:class goodbye {

    public static voidmain(String[] args){

    }

  • 8/6/2019 Java1 Intro

    11/17

    Hmmm

    dir

    hello.class

    goodbye.class

    blah.classfoo.class

    bar.class

    areyouawakein.class

    Java ???

    RunMe.bat:java hello

  • 8/6/2019 Java1 Intro

    12/17

    JBuilder

  • 8/6/2019 Java1 Intro

    13/17

    Java Applets

    Run in a web browser hello.java:import javax.swing.*;

    class hello extends JApplet {

    public voidinit(){

    getContentPane().add(

    new JLabel(Hello World!) );

    }

    }

    javac hello.java

    appletviewer hello HelloWorld!

  • 8/6/2019 Java1 Intro

    14/17

    Java Applets in HTML

    hello.html:

    Need java.

    Put hello.html andhello.class on website

    Java plug-inHelloWorld!

    hello.html

  • 8/6/2019 Java1 Intro

    15/17

    AppletMethods

    init( ) - initialization

    start( ) - resume processing (e.g. animations)

    stop( ) - pause

    destroy( ) - cleanup

    paint( ) - redraw stuff (expose event)

  • 8/6/2019 Java1 Intro

    16/17

    Applet Security

    No read/write on client machine

    Cant execute programs on client machine

    Communicate only with server

    Java applet windowWarning

    Certificates

  • 8/6/2019 Java1 Intro

    17/17

    Upcoming Java Topics

    GUIs: Swing, AWT,MVC

    Event handling, listeners

    Graphics

    Animation, threads

    Components, JavaBeans

    Databases, JDBC