









Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!










Overview
Java GUI Classes JFrame Hierarchy JFrame Structure Event Dispatching Thread GUI Elements – Layout Java Layout Managers
GUI (Graphical User Interface)
Text fields Labels Buttons Checkboxes Radioboxes Menus Tables Etc.
Java GUI Classes
Old GUI framework for Java (Java 1.1) Some reliance on native code counterparts Platform independence problems
New GUI framework first introduced in Java 1.2 Includes AWT features plus many enhancements Pure Java components (no reliance on native code) Pluggable look and feel architecture
How to Create a GUI
JFrame Hierarchy
Several super classes and well asimplemented interfaces Many, member methods includinginherited methods that allow foroperations such as resizing, settingproperties, adding components, etc.
Object Component^ Container
Window^ Frame^ JFrame
Examples
For now our examples have no action associatedwith them. Let’s see example in ex1 package ex2 is basically ex1 but reduced to one class
Event Dispatching Thread (From Wikipedia)
Background thread to process events from the AWTgraphical interface event queue These events are mainly update events that
Cause components to redraw themselves Represent input events
Swing uses a single-threaded painting model whereonly the Event Dispatching thread is the only validthread that can update user interface components Updating components from other threads is a source ofcommon bugs
GUI Elements – Layout
Arrangement of widgets in container
Logical terms (
nd
row, 1
st
column, left)
Preferred approach Actual coordinates (100 pixels, 5 inches)
Can be too rigid, limited to certain window sizes
Entity translating layout specifications into actualcoordinates at runtime, depending on conditions
Java Layout Managers
Lays out components from left to right
Lays out components in a grid of user specified size
Designates portions of the container as North,South, East, West, and Center
Adds components one on top of another
Customizable manager that can use rows andcolumns of varying lengths