Lecture 13: An Introduction to JFC Swing - PowerPoint PPT Presentation

1 / 23
About This Presentation
Title:

Lecture 13: An Introduction to JFC Swing

Description:

5 lectures a revision lecture at the end. Today's Lecture: Intro to interface programming ... Unix (tuck and much): Java 2 (1.4.1) in /usr/bin (or /usr/java) ... – PowerPoint PPT presentation

Number of Views:350
Avg rating:3.0/5.0
Slides: 24
Provided by: ChrisC148
Category:

less

Transcript and Presenter's Notes

Title: Lecture 13: An Introduction to JFC Swing


1
Lecture 13 An Introduction to JFC Swing
G6DHLL High Level Languages
Dr. Natalio Krasnogor Natalio.Krasnogor_at_Nottingham
.ac.uk
2
The Java Section
  • 5 lectures a revision lecture at the end.
  • Todays Lecture
  • Intro to interface programming
  • Intro to Swing
  • Reading list
  • Difference between AWT and Swing
  • Getting Starting with Swing

3
2D interface programming toolkits
  • Tcl/Tk
  • Motif/UIL
  • IDEs (e.g. Microsoft VBasic, VC)
  • Java AWT
  • Java JFC Swing
  • JBuilder and other Java IDEs

4
What is Swing?
  • The Java Foundation Classes
  • Swing
  • Look and feel
  • Accessibility
  • Java 2D (Java 2 onwards)
  • Drag and Drop
  • Interfaces and Applets

5
On-line reading and reference
  • The Swing connection - http//java.sun.com/product
    s/jfc/tsc/
  • The JFC Swing trail -http//java.sun.com/docs/book
    s/tutorial/uiswing/
  • Fundamentals of JFC/Swing I II
    -http//developer.java.sun.com/developer/onlineTra
    ining/

6
Books
  • The JFC Swing Tutorial (1999), K. Walrath and M.
    Campione, Addison Wesley
  • Java Swing (1998), Robert Eckstein, Mark Loy,
    Dave Wood, O'Reilly

7
Getting started with Swing (1)
  • Compiling running programs
  • The Java 1.1 Swing release
  • Swing is standard in Java 2 (JDK 1.2, )
  • Use javac ltprogram.javagt
  • java ltprogramgt

8
Getting started with Swing (2)
  • Computer Science gubbins
  • PCs
  • Java 2 (1.4) on hard disk at \cs\java
  • Unix (tuck and much)
  • Java 2 (1.4.1) in /usr/bin (or /usr/java)
  • Differences between previous versions and 1.4
  • http//java.sun.com/j2se/1.4.2/docs/guide/swing/Sw
    ingChanges.html
  • Java SDK 1.4

9
Getting started with Swing (3)
  • Swing API packages
  • javax.swing, javax.accessibility,
    javax.swing.border
  • At the start of your code - always
  • import javax.swing
  • import javax.swing.event
  • Most Swing programs also need
  • import java.awt.
  • import java.awt.event.

10
Differences between Swing and AWT (1)
  • Never mix Swing and AWT components
  • If you know AWT, put J in front of everything
  • AWT Button
  • Swing JButton
  • Improved capabilities

11
Differences between Swing and AWT (2)
  • Buttons and labels can display images
  • Behaviour and appearance of components
  • Component shape
  • Borders
  • Look and feel of the programs GUI

12
A simple Swing program
  • Containers
  • Components
  • Events
  • Graphics
  • (Threads)

13
A simple Swing program - Containers
  • Containers

14
If you remember one thing about containers,
remember this
  • The structure of container use is your design
    decision and should always be thought about in
    advance
  • particularly for managing components
  • nesting containers

15
A simple Swing program - Components
  • Components

16
If you remember one thing about components,
remember this
  • There are many components that make your job much
    easier
  • Often, you will be able to customise an existing
    Swing component to do a job for you, instead of
    having to start from scratch

17
A simple Swing program - Events
  • Events

18
If you remember one thing about events, remember
this
  • Events as seen by GUIs do not happen all that
    often in an application
  • Consider what is happening between events as well
    as during them

19
A simple Swing program - Graphics
  • Graphics

      
20
If you remember one thing about graphics,
remember this
  • There are many aspects of Swing that allow you to
    achieve graphics-like things without actually
    using Graphics
  • Therefore, you dont have to use them most of the
    time, and it is easier not to

21
A simple Swing program - Threads
  • Most simple Swing GUI applications dont require
    use of any (extra) threads
  • As Swing creates event-driven programs, all code
    is executed on the event-dispatching thread
  • See the example.

22
If you remember one thing about threads, remember
this
  • The single-thread rule
  • Once a Swing component has been realized, all
    code that might affect or depend on the state of
    that component should be executed in the
    event-dispatching thread
  • (with some exceptions)

23
Summary
  • 2D interface programming toolkits
  • JFC/Swing
  • AWT and Swing
  • Getting started with Swing
  • Parts of a simple Swing program
  • Next time Components and Containers
Write a Comment
User Comments (0)
About PowerShow.com