GUI example links
Most of the examples we looked at in lecture class are from the Deitel
textbook. In the current edition, these are chapters 14 and 25. In
edition 7, these were chapters 11 and 22. (They are pretty much the
same examples in either edition).
Links to chapter directories
General notes about the examples
In the first chapter, here are a few notes about the various examples,
as a reference:
- Fig 02 -- Example of JOptionPane usage
- Next 5 examples (fig 06 through 20) introduce the basic components:
- JLabel, JTextField, JButton, JCheckBox, JRadioButton
They also illustrate basic event handling, using private inner classes.
Event listeners shown are ActionListener and
ItemListener
- Next 3 examples (21 through 26) illustrate these components and
event listeners:
- JComboBox, JList, JScrollPane
- ActionListener, ListSelectionListener
A couple of these also use an anonymous inner class for the event
handler
- Next 3 examples (28 through 35) illustrate mouse events. Recall that
these are the mouse handling classes/interfaces:
- MouseListener interface -- 5 methods/events (mouseClicked,
mousePressed, mouseReleased, mouseEntered, mouseExited)
- MouseMotionListener interface -- 2 methods/events
(mouseMoved, mouseDragged)
- There is also a MouseWheelListener interface with just one
event type -- the wheel moving
- MouseEvent is the associated event class, and it has
accessors for retrieving x,y coordinates of the mouse event
- MouseAdapter, MouseMotionAdapter -- associated classes
that already implement the interfaces and define empty method stubs.
Extend these, and you only need to write the methods you want (instead
of all)
- Fig 36_37 shows key events, using interface KeyListener.
Three types:
- keyPressed, keyReleased, keyTyped
- The last 5 examples (39-48) are largely demonstrating layout
managers:
- fig 39_40: FlowLayout
- fig 41_42: BorderLayout
- fig 43_44: GridLayout. Remember that this is a grid of rows and
columns, where each "cell" is the same size
- fig 45_46: illustrates using a panel to mix/match layouts. This
one has a panel with gridlayout of buttons on it, and the panel itself
appears in the south portion of the frame (using BorderLayout)
- fig 47_48: BoxLayout, using helper class Box -- this one
contains some static methods for creating a Box object, which is a panel
with a box layout already on it. This example also shows the
JTextArea component
In the second chapter, there are more examples illustrating various
components, containers, menu use, and then a couple more layout manager
examples:
- Fig 02-04: Shows a JSlider, along with a custom panel with
a drawing on it. Drawing adjusts (and repaints) when the slider is
moved
- Fig 05_06: Good example (and fairly large example), illustrating
how to use the MENU BAR on a frame, and how to create menus, submenus,
and various menu items.
- Fig 07_08: Combining menus and mouse events to create pop-up
menus
- Fig 09_10: Look and feel demo showing the various pre-loaded
look/feels
- Fig 11_12: Illustrating the containers JDesktopPane and
JInternalFrame
- Fig 13_14: Illustrating the container JTabbedPane
- Fig 16_17: Illustrating more details of the BoxLayout manager,
showing various box layouts, including use of struts, glue, etc
- Fig 21_22: GridBagLayout example
- Fig 23_24: another GridBaglayout example