























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!
























Graphical User Interface (GUI)
Interface between user and computer Both input and output Affects usability of computer
Switches & light bulbs Punch cards & teletype (typewriter) Keyboard & black/white monitor (text) Mouse & color monitor (graphics)
Model-View-Controller (MVC)
Model
application data
View
visual interface
Controller
user interaction Model View Controller
MVC Model of GUI Design
Should perform actual work Should be independent of the GUI But can provide access methods
Lets user control what work the program is doing Design of controller depends on model
Lets user see what the program is doing Should not display what controller thinks ishappening (base display on model, not controller)
Creating a GUI in Java
Examples: JFrame, JPanel, JApplet…
Examples: JButton, JTextField, JScrollBar… Use layout manager to determine positions
Add event listeners to GUI components
GUI Elements 1 – Container
Abstractions occupying space in GUI
Usually contain one or more widgets Can be nested in other containers
JFrame, JDialog, JPanel, JScrollPane
JFrame Structure Most things go intocontent pane getContentPane() Use glassPane for pop upmenus, some animations Methods getRootPane() getLayeredPane() getContentPane() getGlassPane() Can set…Pane explicitly glassPane rootPane JFrame layeredPane LayeredPane contains contentPane LayeredPane manages (optional) JMenuBar
GUI Elements 2 – Component
Actual items (widgets) user sees in GUI
Labels (fixed text) Text areas (for entering text) Buttons Checkboxes Tables Menus Toolbars Etc…
Java Components
Java Components
Java Components
Each JTable object Gets its data from an object implementingTableModel interface Displays contents of TableModel object DefaultTableModel class implements TableModel Many different ways to use JTable to display data
Layout
Arrangement of GUI components 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
Java Layout Manager
Lays out components from left to right
Java Layout Manager
Designates portions of the container as North,South, East, West, and Center