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

Slides:



Advertisements
Similar presentations
JustinMind: Dynamic Panels
Advertisements

Graphic User Interfaces Layout Managers Event Handling.
Corresponds with Chapter 12
Chapter 6 Graphical User Interface (GUI) and Object-Oriented Design (OOD)
Java Programming, 3e Concepts and Techniques Chapter 5 Arrays, Loops, and Layout Managers Using External Classes.
Lecture 15 Graphical User Interfaces (GUI’s). Objectives Provide a general set of concepts for GUI’s Layout manager GUI components GUI Design Guidelines.
Swing CS-328 Dick Steflik John Margulies. Swing vs AWT AWT is Java’s original set of classes for building GUIs Uses peer components of the OS; heavyweight.
1 GUI Elements in Java Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
GUI and Event-Driven Programming Part 2. Event Handling An action involving a GUI object, such as clicking a button, is called an event. The mechanism.
10.1 AWT The AWT classes Users today expect a Graphical User Interface (GUI) Improves application usability Difficult to implement cross-platform.
Chapter 6 Graphical User Interface (GUI) and Object-Oriented Design (OOD)
Chapter 6: Graphical User Interface (GUI) and Object-Oriented Design (OOD) J ava P rogramming: Program Design Including Data Structures Program Design.
Access Tutorial 10 Automating Tasks with Macros
Chapter 9 Macros, Navigation Forms, PivotTables, and PivotCharts
Graphic User Interfaces Part 1. Typical GUI Screen from Microsoft Word What GUI “components” can you see? –Menus? Buttons? Labels? What else? –Anything.
Chapter 3 Working with Symbols and Interactivity.
Java Programming Chapter 10 Graphical User Interfaces.
Unit J: Creating a Database Microsoft Office Illustrated Fundamentals.
Java Programming, 3e Concepts and Techniques Chapter 3 Section 65 – Manipulating Data Using Methods – Java Applet.
Java Software Solutions Lewis and Loftus Chapter 10 1 Copyright 1997 by John Lewis and William Loftus. All rights reserved. Graphical User Interfaces --
© 2011 Delmar, Cengage Learning Chapter 3 Working with Symbols and Interactivity.
Java Programming: From Problem Analysis to Program Design, Second Edition1  Learn about basic GUI components.  Explore how the GUI components JFrame,
CIS 068 Welcome to CIS 083 ! Introduction to GUIs: JAVA Swing.
DAT602 Database Application Development Lecture 6 JAVA Swing.
Applets and Frames CS 21a: Introduction to Computing I First Semester,
MIT AITI 2003 Lecture 17. Swing - Part II. The Java Event Model Up until now, we have focused on GUI's to present information (with one exception) Up.
3461A Readings from the Swing Tutorial. 3461A Overview  The follow is the Table of Contents from the trail “Creating a GUI with JFC/Swing” in the “The.
Java SE 8 for Programmers, Third Edition
Ch 3-4: GUI Basics Java Software Solutions Foundations of Program Design Sixth Edition by Lewis & Loftus Coming up: GUI Components.
Java Swing. Swing is a set of classes that provides more powerful and flexible components than are possible with the AWT. In addition to the familiar.
Graphic User Interface. Graphic User Interface (GUI) Most of us interact with computers using GUIs. GUIs are visual representations of the actions you.
Liang, Introduction to Java Programming, Fifth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 33 Advanced Java.
Copyright © 2002, Systems and Computer Engineering, Carleton University c-Gui3.ppt * Object-Oriented Software Development Part 18-c Building.
MSc Workshop - © S. Kamin, U. ReddyLect 3 - GUI -1 Lecture 3 - Graphical User Interfaces r GUI toolkits in Java API r JFrame r GUI components.
Timer class and inner classes. Processing timer events Timer is part of javax.swing helps manage activity over time Use it to set up a timer to generate.
Applets and Frames. Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved L14: GUI Slide 2 Applets Usually.
JAVA: An Introduction to Problem Solving & Programming, 6 th Ed. By Walter Savitch ISBN © 2012 Pearson Education, Inc., Upper Saddle River,
Object-Oriented Program Development Using Java: A Class-Centered Approach, Enhanced Edition.
Java Programming Applets. Topics Write an HTML document to host an applet Understand simple applets Use Labels with simple AWT applets Write a simple.
Creating Windows. How can we use Java to create programs that use windows (GUI applications)? How can we use Java to create programs that use windows.
CS324e - Elements of Graphics and Visualization Java GUIs - Event Handling.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Chapter 15 Creating User.
Introduction to GUI in 1 Graphical User Interface 2 Nouf Almunyif.
CHAPTER:08 JAVA IDE PROGRAMMING-III Prepared By Prepared By : VINAY ALEXANDER ( विनय अलेक्सजेंड़र ) PGT(CS),KV JHAGRAKHAND.
Copyright © 2015 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 13 GUI Programming.
Java Programming: From Problem Analysis to Program Design, 3e Chapter 6 Graphical User Interface (GUI) and Object-Oriented Design (OOD)
GUIs Graphical User Interfaces. Everything coming together Known: – Inheritance – Interfaces – Abstract classes – Polymorphism – Exceptions New: – Events.
Swing. Introduction to Swing What is Swing? “ Swing is a diverse collection of lightweight components that can be used to build sophisticated user interfaces.”
Creating User Interfaces Chapter 13 CSCI CSCI 1302 – Creating User Interfaces2 Outline Introduction Common Features of Swing GUI Components Buttons.
Java Programming, Second Edition Chapter Thirteen Understanding Swing Components.
Chapter 14: Introduction to Swing Components. Objectives Understand Swing components Use the JFrame class Use the JLabel class Use a layout manager Extend.
JAVA: An Introduction to Problem Solving & Programming, 6 th Ed. By Walter Savitch ISBN © 2012 Pearson Education, Inc., Upper Saddle River,
Chapter 10 - Writing Graphical User Interfaces1 Chapter 10 Writing Graphical User Interfaces.
Graphical User Interface (GUI)
Chapter 6 Graphical User Interface (GUI) and Object-Oriented Design (OOD)
Introduction to GUI Programming in Java: Frames, Simple Components, and Layouts.
CIS 270—Application Development II Chapter 11—GUI Components: Part I.
Chapter 7 Creating Templates, Importing Data, and Working with SmartArt, Images, and Screen Shots Microsoft Excel 2013.
Java Programming Fifth Edition Chapter 13 Introduction to Swing Components.
GUIs & Event-Driven Programming Chapter 11 Review.
A First Look at GUI Applications Radio Buttons and Check Boxes
A First Look at GUI Applications
Processing Timer Events
Graphical User Interface (pronounced "gooey")
Chap 7. Building Java Graphical User Interfaces
Graphical User Interfaces -- Introduction
Timer class and inner classes
Constructors, GUI’s(Using Swing) and ActionListner
Unit J: Creating a Database
Presentation transcript:

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

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

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.

Typical approach to working with tabbed panes

Tab 1 has the label Tab 2 has the panel containing a label and a text field

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).

ToolBarDemo This class includes buttons and a textfield to put into the toolbar

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

Remember that you can set tooltips for JButtons

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

For JButtons with images, it may be more aesthetically pleasing to hide the borders.

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.

Toolbar can be docked in many places on the frame, or even outside of it.

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)

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)

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

Simple example using JTable, Vector, JScrollPane

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.

Here we set up the column-header vector by adding strings to it. There will be a total of four columns in this example.

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.

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.

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

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

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

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

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