Title: Notes for Assignment
1Notes for Assignment 2
- Assn2
- GUI Database Interface
- Corresponds with Chapters 28, 29, 31
2About Assignment 2
- GUI Features
- Toolbars
- Buttons with Images
- Tabbed Panes
- Scrollable Tables
- Scrollable Lists
- Query requirements
- Multitable joins
- Aggregate functions with grouping
- Subqueries
3JTabbedPane
- A component that lets the user switch between a
group of components by clicking on a tab with a
given title and/or icon - Constructors
- JTabbedPane()
- Adding Tabs
- addTab(tabname,component)
- Places the specified component into the tabl and
gives it the specified name.
4Typical approach to working with tabbed panes
5Tab 1 has the label
Tab 2 has the panel containing a label and a text
field
6Toolbars
- JToolbar - this component will contain other
components (usually JButtons), and will be placed
on a region of the frame (typically North in a
BorderLayout). - Note that JToolbars are dockable (can be moved
around). - Toolbar buttons can be any type of button.
- As with any button, toolbar buttons will generate
action events (and perhaps item events if they
are boolean-state buttons).
7ToolBarDemo
This class includes buttons and a textfield to
put into the toolbar
8JButton allows images as an alternative to text
labels You can do this using the ImageIcon
class ImageIcon contstructor takes as an
argument the full path to a graphic file
(typically .gif or .jpg) Overloaded JButton
constructor can take ImageIcon reference as an
argument
9Remember that you can set tooltips for JButtons
10Remember that you can set aaction commands for
JButtons
Also remember that you need to register the
action listener for your JButtons
This way, when an action event occurs, you can
use the action command to decide what to do
11For JButtons with images, it may be more
aesthetically pleasing to hide the borders.
12Like any container, you add components to the
JToolbar. These will be added left-to-right. Typi
cally, you want the toolbar at the top of the
content pane of your frame.
13Toolbar can be docked in many places on the
frame, or even outside of it.
14JTable
- component that presents data in a two-dimensional
table format - Can be associated with arrays or Vectors
- NOTE Vectors are dynamically resizable arrays
whose elements point to instances of Object (or
subclasses) - Constructors
- JTable(DataArray,ColumnNameArray)
- JTable(DataVector,ColumnNameVector)
15JScrollPane
- Provides a scrollable view of any lightweight
Swing component - Constructor
- JScrollPane(anyComponent)
16The Vector Class
- in the java.util package
- resizable array containing references to Object
instances (or instances of Object subclasses) - Can be indexed
- Can have elements added and deleted
- Some useful methods
- elementAt(int) returns the object referenced by
specified element - addElement(Object) adds the object to the end
of the Vector - removeElementAt(int) deletes the element at the
specified index - removeAllElements() empties out the vector
17Simple example using JTable, Vector, JScrollPane
18A JTable will require two collections (vectors or
arrays). There will be a 2D vector or array
containing the data displayed in the
table. There will also be a 1D array or vector
containing the column headers.
19Here we set up the column-header vector by adding
strings to it. There will be a total of four
columns in this example.
20Here we set up the data vector for the
JTable. Note that this is a vector of vectors
(that is, a 2-dimensional vector). Therefore, it
is created using a nested loop. Outer loop sets
up the rows, inner loop sets up the specific
elements within a row.
21In order to ensure that the JTable is scrollable,
we put it into a JScrollPane. We add the
JScrollPane to the frame instead of directly
adding the JTable to the frame.
22(No Transcript)
23Combining GUI Features
- The following example includes several GUI
features - Toolbars
- Tabbed Panes
- Tables in scrollpanes
- In addition, it shows how you can replace
components in a tab during program execution
24Sample Execution
When application first runs, before user selection
User selects 5 rows, 3 columns
User selects 10 rows, 2 columns
25(No Transcript)
26Constructor establishes Toolbar Tabbed
pane Button listener
27This is a handy class for associating a label
with a component (you had it for CIS 331 also).
28(No Transcript)