Gui Programming: Session 1 Introduction To Gui Design Lecturer: Luke Raeside, PHD
Gui Programming: Session 1 Introduction To Gui Design Lecturer: Luke Raeside, PHD
GUI Programming
Session 1
Introduction to GUI Design
1
Programming with with
GUI Programming JAVAJAVA
Objectives
Session 1 Introduction to GUIs
We will look at
2
Programming with with
GUI Programming JAVAJAVA
Session 1 Introduction to GUIs
Background to GUIs
3
Programming with with
GUI Programming JAVAJAVA
Session 1 Introduction to GUIs
What is a GUI?
pronounced "gooey".
4
Programming with with
GUI Programming JAVAJAVA
Session 1 Introduction to GUIs
Definitions
5
Programming with with
GUI Programming JAVAJAVA
Session 1 Introduction to GUIs
6
Programming with with
GUI Programming JAVAJAVA
Session 1 Introduction to GUIs
Whats in a GUI?
8
Programming with with
GUI Programming JAVAJAVA
Session 1 Introduction to GUIs
9
Programming with with
GUI Programming JAVAJAVA
Session 1 Introduction to GUIs
11
Programming with with
GUI Programming JAVAJAVA
Session 1 Introduction to GUIs
12
Programming with with
GUI Programming JAVAJAVA
Session 1 Introduction to GUIs
5. Error prevention
13
Programming with with
GUI Programming JAVAJAVA
Session 1 Introduction to GUIs
14
Programming with with
GUI Programming JAVAJAVA
Session 1 Introduction to GUIs
15
Programming with with
GUI Programming JAVAJAVA
Session 1 Introduction to GUIs
16
Programming with with
GUI Programming JAVAJAVA
Session 1 Introduction to GUIs
17
Programming with with
GUI Programming JAVAJAVA
Session 1 Introduction to GUIs
18
Programming with with
GUI Programming JAVAJAVA
Session 1 Introduction to GUIs
GUIs in JAVA
19
Programming with with
GUI Programming JAVAJAVA
Session 1 Introduction to GUIs
When JAVA 1.0 was introduced, it contained a class library which SUN
called the Abstract Window Toolkit or AWT.
AWT was used for basic GUI programming. The way AWT library deals with
user interface elements is to delegate their creation and behaviour to the
native GUI toolkit on each target platform (Windows, MAC, Linux etc).
JAVA would just be responsible for creating the peers. The idea was that
you could write once and run anywhere.
20
Programming with with
GUI Programming JAVAJAVA
Session 1 Introduction to GUIs
The peer based approach worked well for simple applications but it soon
became apparent that it was very difficult to create complex GUI JAVA
based applications that could run on a variety of platforms.
User interface elements such as menus, scrollbars and text fields can have
subtle differences or behaviours on different platforms.
As a result applications built in JAVA with AWT did not look as nice/slick as
native Windows or Macintosh applications.
More seriously different bugs existed in the AWT UI library for different
platforms. Developers complained that they needed to test their
applications on each platform , a practice called write once debug
everywhere.
21
Programming with with
GUI Programming JAVAJAVA
Session 1 Introduction to GUIs
In 1996 Netscape created a GUI library called the IFC (Internet Foundation
Classes) that used and entirely different approach.
Thus Netscape's IFC widgets looked and behaved the same no matter what
platform they were run on.
Sun worked with Netscape to perfect this approach creating a user interface
library with the codename SWING (sometimes called the SWING set).
The full JFC is vast and far more that just the SWING GUI toolkit. The JFC
also features components for accessibility, a 2D API and a drag and drop
API.
22
Programming with with
GUI Programming JAVAJAVA
Session 1 Introduction to GUIs
Swing has a much richer and convenient set of user interface elements.
23
Programming with with
GUI Programming JAVAJAVA
Session 1 Introduction to GUIs
AWT was built initially as a quick solution to the need for write once run
anywherebut relied on peer components in the specific architectures too
much, i.e. there were too many heavyweight components
Heavyweight components are those that are associated with a native peer
component and are rendered in their own native opaque window
24
Programming with with
GUI Programming JAVAJAVA
Session 1 Introduction to GUIs
Since Swing was released AFTER AWT, Swing has also removed many of
the software bugs that were in the AWT
Swing components, even though they mimic the AWT behaviors also add
new features e.g. buttons with images
25
Programming with with
GUI Programming JAVAJAVA
Session 1 Introduction to GUIs
Lightweight components make the write once run anywhere goal more
achievable since there is no platform dependence
26
Programming with with
GUI Programming JAVAJAVA
Session 1 Introduction to GUIs
SWING Classes
27
Programming with with
GUI Programming JAVAJAVA
Session 1 Introduction to GUIs
Swing does not use AWT components with the exception of extending the Frame,
Window and Dialog heavyweight components to create JFrame, JWindow and
JDialog (these are still heavyweight in Swing)
Like all good Object Oriented systems Swing RE-USES the best of AWT in order to
build more lightweight components
28
Programming with with
GUI Programming JAVAJAVA
Session 1 Introduction to GUIs
The biggest issues arises when trying to add a heavyweight component into
a lightweight component
So the upshot is dont mix SWING and AWT components in your software
(i.e. dont use a SWING button in an AWT interface and visa versa)
29
Programming with with
GUI Programming JAVAJAVA
Session 1 Introduction to GUIs
SWING Classes
30
Programming with with
GUI Programming JAVAJAVA
Session 1 Introduction to GUIs
JTextField An area in which the user inputs data from the keyboard. The area can also
display information.
JComboBox A drop down list of items from which the user can make a selection by clicking
an item on the list.
A drop down list of items from which the user can make a selection by clicking
JList once on any element in the list. Double clicking on any element in the list
generates an action event.
31
Programming with with
GUI Programming JAVAJAVA
Session 1 Introduction to GUIs
SWT
The good news for developers is that its coding is very similar to
SWING. So if you can program in SWING, you will have no
problems moving to SWT (if required)
32
Programming with with
GUI Programming JAVAJAVA
Session 1 Introduction to GUIs
33
Programming with with
GUI Programming JAVAJAVA
Session 1 Introduction to GUIs
Developing GUIs
34
Programming with with
GUI Programming JAVAJAVA
Session 1 Introduction to GUIs
Swing Designer
NetBeans
JFormDesigner
FormLayoutMaker
Foam
Once you have defined your GUI, in what format does the GUI
builder save it?
Pure code. The tool generates Java code to create the GUI, and parses
Java code to read it into the visual editor. It does not save any files
other than the Java code.
Code and metadata. The tool generates metadata describing the forms,
as well as Java code to display the forms. An example is NetBeans,
which saves the form definition in .form files and generates code in .java
files. The .form files live in the same directory as the corresponding
.java file.
35
Programming with with
GUI Programming JAVAJAVA
Session 1 Introduction to GUIs
36
Programming with with
GUI Programming JAVAJAVA
Session 1 Introduction to GUIs
http://download.oracle.com/javase/tutorial/uiswin
g/start/index.html
37
Programming with with
GUI Programming JAVAJAVA
Session 1 Introduction to GUIs
End of Session
Labwork 1:
38