






Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
This document from the university of maryland, college park's department of computer science outlines the java gui classes, container components, and event handling in the context of the cmsc 132 course. It covers awt, swing, and swt, as well as layout managers and event dispatching threads.
Typology: Study notes
1 / 10
This page cannot be seen from the preview
Don't miss anything!







1
2
Component ⇒ items displayed (widgets) Container ⇒ region containing components Layout ⇒ arrangement of components Event ⇒ interactions for GUI
3
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. Includes AWT features plus many enhancements Pure Java components (no reliance on native code) Pluggable look and feel architecture
4
Java GUI Classes
Component classes Items (widgets) displayed in GUI JButton, JTextField, JDialog, JScrollBar… Container classes Hold GUI Components JFrame, JPanel, JApplet… Helper classes Describe properties of other GUI components Color, Graphics, Dimension…
7
Java Components
With three JButtons
8
JFrame Hierarchy
Several super classes As well as implemented interfaces
Many, many member methods Including inherited methods that allow Resizing Setting properties Adding components, Etc…
Other top level containers JDialog (dialog boxes) JApplet (web applets) JWindow (stripped down JFrame, no title bar or window buttons)
Object
Component
Container
Window
Frame
JFrame
9
JFrame Structure
Most things go into content pane getContentPane() Use glassPane for pop up menus, some animations Methods getRootPane() getLayeredPane() getContentPane() getGlassPane() Can set…Pane explicitly
glassPane
rootPane
JFrame
layeredPane
LayeredPane contains contentPane
LayeredPane manages (optional) JMenuBar
10
GUI Elements – Layout
Arrangement of GUI components in container
Logical terms (2nd^ row, 1st^ column, left) Preferred approach Actual coordinates (100 pixels, 5 inches) Can be too rigid, limited to certain window sizes
Entity translating layout specifications into actual coordinates at runtime, depending on conditions
13
Java Components
14
Java Components
15
Java Components
16
Java Components
Each JTable object Gets its data from an object implementing TableModel interface Displays contents of TableModel object DefaultTableModel class implements TableModel Many different ways to use JTable to display data
19
Event Dispatching Thread
Allows current thread to execute GUI code in dispatching thread createAndDisplayGUI Method that actually defines the GUI
javax.swing.SwingUtilities.invokeLater(new Runnable( ) { public void run( ) { createAndDisplayGUI( ); } });
20
Java Support For GUIs
Appendix C of textbook Javadoc for the JDK Swing tutorial Course slides and code handouts Java Ranch