Presentation is loading. Please wait.

Presentation is loading. Please wait.

Notes for Assignment #2 Assn2: GUI Database Interface Corresponds with Chapters 28, 29, 31.

Similar presentations


Presentation on theme: "Notes for Assignment #2 Assn2: GUI Database Interface Corresponds with Chapters 28, 29, 31."— Presentation transcript:

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

2 About Assignment #2 GUI Features: GUI Features: Toolbars Toolbars Buttons with Images Buttons with Images Tabbed Panes Tabbed Panes Scrollable Tables Scrollable Tables Scrollable Lists Scrollable Lists Query requirements Query requirements Multitable joins Multitable joins Aggregate functions with grouping Aggregate functions with grouping Subqueries 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 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 Constructors JTabbedPane() JTabbedPane() JTabbedPane Adding Tabs: Adding Tabs: addTab(tabname,component) addTab(tabname,component) Places the specified component into the tabl and gives it the specified name. 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). 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). Note that JToolbars are dockable (can be moved around). Toolbar buttons can be any type of button. 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). 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 This way, when an action event occurs, you can use the action command to decide what to do Also remember that you need to register the action listener for your JButtons

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. Typically, 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 component that presents data in a two-dimensional table format Can be associated with arrays or Vectors Can be associated with arrays or Vectors NOTE: Vectors are dynamically resizable arrays whose elements point to instances of Object (or subclasses) NOTE: Vectors are dynamically resizable arrays whose elements point to instances of Object (or subclasses) Constructors Constructors JTable(DataArray[][],ColumnNameArray[]) JTable(DataArray[][],ColumnNameArray[]) JTable(DataVector,ColumnNameVector) JTable(DataVector,ColumnNameVector)

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

16 The Vector Class in the java.util package in the java.util package resizable array containing references to Object instances (or instances of Object subclasses) resizable array containing references to Object instances (or instances of Object subclasses) Can be indexed Can be indexed Can have elements added and deleted Can have elements added and deleted Some useful methods: Some useful methods: elementAt(int) – returns the object referenced by specified element elementAt(int) – returns the object referenced by specified element addElement(Object) – adds the object to the end of the Vector addElement(Object) – adds the object to the end of the Vector removeElementAt(int) – deletes the element at the specified index removeElementAt(int) – deletes the element at the specified index removeAllElements() – empties out the vector 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

23 Combining GUI Features The following example includes several GUI features: The following example includes several GUI features: Toolbars Toolbars Tabbed Panes Tabbed Panes Tables in scrollpanes Tables in scrollpanes In addition, it shows how you can replace components in a tab during program execution In addition, it shows how you can replace components in a tab during program execution

24 Sample Execution User selects 5 rows, 3 columns User selects 10 rows, 2 columns When application first runs, before user selection

25

26 Constructor establishes: Toolbar Tabbed pane Button listener Setting up combo boxes

27 This is a handy class for associating a label with a component (you had it for CIS 331 also).

28 Place scrollable JTable into a Tab index NOTE: the JTabbedPane class’s setComponentAt method takes two arguments: 1)The index number of the tab (0-based indexing) 2)The component that is to be placed into the tab at the given index position. When you want to change the table in the tab, you need to call setComponentAt Instantiate JTable based on header and data vectors Create header and data vectors Determine nbr of rows and columns


Download ppt "Notes for Assignment #2 Assn2: GUI Database Interface Corresponds with Chapters 28, 29, 31."

Similar presentations


Ads by Google