Notes for Assignment - PowerPoint PPT Presentation

1 / 28
About This Presentation
Title:

Notes for Assignment

Description:

Provides a scrollable view of any lightweight Swing component. Constructor ... Outer loop sets up the rows, inner loop sets up the specific elements within a row. ... – PowerPoint PPT presentation

Number of Views:17
Avg rating:3.0/5.0
Slides: 29
Provided by: mikem52
Category:
Tags: assignment | notes | sets | swing

less

Transcript and Presenter's Notes

Title: Notes for Assignment


1
Notes for Assignment 2
  • Assn2
  • GUI Database Interface
  • Corresponds with Chapters 28, 29, 31

2
About Assignment 2
  • GUI Features
  • Toolbars
  • Buttons with Images
  • Tabbed Panes
  • Scrollable Tables
  • Scrollable Lists
  • Query requirements
  • Multitable joins
  • Aggregate functions with grouping
  • Subqueries

3
JTabbedPane
  • 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.

4
Typical approach to working with tabbed panes
5
Tab 1 has the label
Tab 2 has the panel containing a label and a text
field
6
Toolbars
  • 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).

7
ToolBarDemo
This class includes buttons and a textfield to
put into the toolbar
8
JButton 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
9
Remember that you can set tooltips for JButtons
10
Remember 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
11
For JButtons with images, it may be more
aesthetically pleasing to hide the borders.
12
Like 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.
13
Toolbar can be docked in many places on the
frame, or even outside of it.
14
JTable
  • 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)

15
JScrollPane
  • Provides a scrollable view of any lightweight
    Swing component
  • Constructor
  • JScrollPane(anyComponent)

16
The 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

17
Simple example using JTable, Vector, JScrollPane
18
A 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.
19
Here we set up the column-header vector by adding
strings to it. There will be a total of four
columns in this example.
20
Here 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.
21
In 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)
23
Combining 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

24
Sample Execution
When application first runs, before user selection
User selects 5 rows, 3 columns
User selects 10 rows, 2 columns
25
(No Transcript)
26
Constructor establishes Toolbar Tabbed
pane Button listener
27
This is a handy class for associating a label
with a component (you had it for CIS 331 also).
28
(No Transcript)
Write a Comment
User Comments (0)
About PowerShow.com