You are on page 1of 49

Graphic User Interfaces (GUIs)

Second Session
Object Oriented Programming

Graphic User Interfaces (GUIs)


Agenda

Main Java AWT and


AWT &
GUIs Swing
SWING
Components Examples

Graphic User Interfaces (GUIs)


AWT & SWING

AWT & SWING


SWING Components
AWT is first Java classes for building GUIs

Graphic User Interfaces (GUIs)


Java applets can be inserted directly in web pages

Java Code

HTML Code

Graphic User Interfaces (GUIs)


Java applets can be inserted directly in web pages

Java Code

HTML Code

Graphic User Interfaces (GUIs)


Java applets can be inserted directly in web pages

Java Code

Java Applets are old


technology!!!

HTML Code

Graphic User Interfaces (GUIs)


AWT vs Swing

Abstract Windows Toolkit (AWT) Swing was an attempt to solve most


is the original Java GUI tool kit of AWT's shortcomings.

Look (appearance) and feel (how it reacts to input events)

Graphic User Interfaces (GUIs)


AWT
Components

Graphic User Interfaces (GUIs)


Containers
and
Controls Windows

Menu

Layouts
AWT
Components

Swing
Components
AWT Events

Graphic User Interfaces (GUIs)


Menus

Windows

Controls
Containers

Text
controls
Java Swing
and AWT
Components

Graphic User Interfaces (GUIs)


Main Java GUIs Components

Windows
Containers
Controls
Component class

The superclass of
allgraphic
GUIsComponent

Graphic User Interfaces (GUIs)


Some useful Components methods

Graphic User Interfaces (GUIs)


Main Components can be of three types

Window

Container 1

Control 1

Container 2
Control 2

Control 3

Main Components can be grouped hierarchically

Graphic User Interfaces (GUIs)


Windows Components

Graphic User Interfaces (GUIs)


Windows are the main components of Swing

File Chooser
Frame

Option Pane Color Chooser

Graphic User Interfaces (GUIs)


A JFrame is a top-level window with a title and a border

1
2
3

How to make Frames

Graphic User Interfaces (GUIs)


A JFileChooser is used to Save, Open or Select Files

3
4

How to Use File Choosers

Graphic User Interfaces (GUIs)


A JOptionPane is used to show standard dialogs

How to Make Dialogs

Graphic User Interfaces (GUIs)


A JOptionPane is used to show standard dialogs

How to Make Dialogs

Graphic User Interfaces (GUIs)


A JDialog is used to show specialized messages

How to Make Dialogs

Graphic User Interfaces (GUIs)


A JColorChooser is used for color selection

How to Use Color Choosers

Graphic User Interfaces (GUIs)


Control Components

Graphic User Interfaces (GUIs)


A JLabel is used to
display unselectable
text and images

How to Use Labels


Graphic User Interfaces (GUIs)
A JButton is used for
executing users actions

How to Use Buttons


Graphic User Interfaces (GUIs)
A JCheckBox is used for selecting several options

How to Use Check Boxes

Graphic User Interfaces (GUIs)


A JRadioButton is used for selecting one option in a group

How to Use Radio Buttons

Graphic User Interfaces (GUIs)


A JComboBox is used for selecting one of several options

How to Use Combo Boxes

Graphic User Interfaces (GUIs)


A JList is used to show items in one or many columns

How to Use Lists

Graphic User Interfaces (GUIs)


A JTextField enables the user to type a small amount of text

How to Use Text Fields

Graphic User Interfaces (GUIs)


A JPasswordField enables the user to type a secret text

How to Use Password Fields

Graphic User Interfaces (GUIs)


A JTextArea enables the user to type several text lines

How to Use Text Areas

Graphic User Interfaces (GUIs)


A JSlider enables the user to enter a bounded numeric value

How to Use Sliders

Graphic User Interfaces (GUIs)


A JToggleButton is similar to a JButton, but with two states

Graphic User Interfaces (GUIs)


A JFormattedField
is used for
specifying the valid
set of characters
that can be typed in
a text field

Graphic User Interfaces (GUIs) How to Use Formatted Text Fields


A JTree is used fordisplaying hierarchical data

How to Use Trees

Graphic User Interfaces (GUIs)


A JTable is used to display tables of data

How to Use Tables

Graphic User Interfaces (GUIs)


A JSpinner lets the user to choose from a range of values

How to Use Spinners

Graphic User Interfaces (GUIs)


Container Components

Graphic User Interfaces (GUIs)


Containers are used to organize other components

Graphic User Interfaces (GUIs)


A JPanel is
a general
purpose
container

How to Use Panels


Graphic User Interfaces (GUIs)
AJSplitPanedisplays two components

How to Use Split Panes

Graphic User Interfaces (GUIs)


A JTabbedPane is used for sharing the same space

How to Use Tabbed Panes

Graphic User Interfaces (GUIs)


A JScrollPane provides a scrollable view of a component

Use a scroll pane to display a component that


is large or one whose size can change
dynamically
How to Use Scroll Panes

Graphic User Interfaces (GUIs)


Geometrics

The Java 2D API provides several


classes that define common
geometric objects such as points,
lines, curves, and rectangles. These
geometry classes are part of the
java.awt.geompackage.

Working with Geometry

Graphic User Interfaces (GUIs)


References

Java AWT Package Example


http://www.roseindia.net/java/example/java/awt/index.shtml

Swing components gallery


http://www.javamex.com/tutorials/swing/components.shtml

Java in a Nutshell By David Flanagan


http://docstore.mik.ua/orelly/java/javanut/index.htm

Graphic User Interfaces (GUIs)

You might also like