Title: Lecture 13: An Introduction to JFC Swing
1Lecture 13 An Introduction to JFC Swing
G6DHLL High Level Languages
Dr. Natalio Krasnogor Natalio.Krasnogor_at_Nottingham
.ac.uk
2The 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
32D interface programming toolkits
- Tcl/Tk
- Motif/UIL
- IDEs (e.g. Microsoft VBasic, VC)
- Java AWT
- Java JFC Swing
- JBuilder and other Java IDEs
4What is Swing?
- The Java Foundation Classes
- Swing
- Look and feel
- Accessibility
- Java 2D (Java 2 onwards)
- Drag and Drop
- Interfaces and Applets
5On-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/
6Books
- The JFC Swing Tutorial (1999), K. Walrath and M.
Campione, Addison Wesley - Java Swing (1998), Robert Eckstein, Mark Loy,
Dave Wood, O'Reilly
7Getting 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
8Getting 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
9Getting 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.
10Differences 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
11Differences 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
12A simple Swing program
- Containers
- Components
- Events
- Graphics
- (Threads)
13A simple Swing program - Containers
14If 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
15A simple Swing program - Components
16If 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
17A simple Swing program - Events
18If 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
19A simple Swing program - Graphics
20If 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
21A 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.
22If 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)
23Summary
- 2D interface programming toolkits
- JFC/Swing
- AWT and Swing
- Getting started with Swing
- Parts of a simple Swing program
- Next time Components and Containers