Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Graphical User Interfaces Revisited Material from Chapters 7 - 10.

Slides:



Advertisements
Similar presentations
Prof. Yitzchak Rosenthal
Advertisements

ELC 310 Day 21. © 2004 Pearson Addison-Wesley. All rights reserved10-2 Agenda Questions? Capstone Proposals Overdue  4 Submitted  3 Accepted, 1 in negotiations.
ITEC220 GUI Lecture – Part 2 References  Java Software Solutions,” by Lewis & Loftus  Chapter 7  Chapter 8  Chapter 9  Java Foundations-Introduction.
Unit 131 GUI Layout Managers and Components, Continue Card Layout Borders More GUI components Menu List Sliders Combo Boxes Scroll Panes Split Panes Special.
Chapter 9: Graphical User Interfaces Copyright 2002, Matthew Evett. These slides are based on slides copyrighted by John Lewis and William Loftus, 2002,
Chapter 9 Polymorphism. © 2004 Pearson Addison-Wesley. All rights reserved9-2 Polymorphism Polymorphism (having many forms) is an object- oriented concept.
© The McGraw-Hill Companies, 2006 Chapter 18 Advanced graphics programming.
Chapter Day 23. © 2007 Pearson Addison-Wesley. All rights reserved Agenda Day 23 Problem set 4 Due Problem set 5 Posted (Last one)  Due Dec 8 Capstones.
Chapter Day 10. © 2007 Pearson Addison-Wesley. All rights reserved4-2 Agenda Day 10 Questions from last Class?? Problem set 2 posted  10 programs from.
Chapter 8: Animation Copyright 2002, Matthew Evett. These slides are based on slides copyrighted by John Lewis and William Loftus, 2002, and used with.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Java Software Solutions Foundations of Program Design Sixth Edition by Lewis.
Chapter Day 22. © 2007 Pearson Addison-Wesley. All rights reserved Agenda Day 22 Problem set 4 Posted  10 problems from chapters 7 & 8  Due Nov 21 (right.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Java Software Solutions Foundations of Program Design Sixth Edition by Lewis.
Chapter Day 25. © 2007 Pearson Addison-Wesley. All rights reserved Agenda Day 25 Problem set 5 Posted (Last one)  Due Dec 8 Capstones Schedule  3rd.
Chapter 9 Polymorphism 5 TH EDITION Lewis & Loftus java Software Solutions Foundations of Program Design © 2007 Pearson Addison-Wesley. All rights reserved.
1 GUI Elements in Java Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
Chapter Day 21. © 2007 Pearson Addison-Wesley. All rights reserved7-2 Agenda Day 20 Problem set 4 Posted  10 problems from chapters 7 & 8  Due Nov 21.
Chapter Day 9. © 2007 Pearson Addison-Wesley. All rights reserved4-2 Agenda Day 8 Questions from last Class?? Problem set 2 posted  10 programs from.
Chapter Day 19. © 2007 Pearson Addison-Wesley. All rights reserved7-2 Agenda Day 19 Problem set 3 Corrected  1 A, 2 B’s and 1 D Problem set 4 Posted.
ELC 312 Day 16. © 2004 Pearson Addison-Wesley. All rights reserved Agenda Questions? Capstone Proposals Due Problem set 3 Corrected  Poor performance.
© 2004 Pearson Addison-Wesley. All rights reserved8-1 Chapter 8 : Inheritance Intermediate Java Programming Summer 2007.
Microsoft Visual Basic 2012 CHAPTER TWO Program and Graphical User Interface Design.
10-1 Exceptions An exception is an object that describes an unusual or erroneous situation Exceptions are thrown by a program, and may be caught and handled.
Java Software Solutions Lewis and Loftus Chapter 10 1 Copyright 1997 by John Lewis and William Loftus. All rights reserved. Graphical User Interfaces --
Liang, Introduction to Java Programming, Fifth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 13 Creating User.
1 CSC111H Graphical User Interfaces (GUIs) Introduction GUIs in Java Understanding Events A Simple Application The Containment Hierarchy Layout Managers.
Visual Basic 2005 CHAPTER 2 Program and Graphical User Interface Design.
McGraw-Hill/Irwin The Interactive Computing Series © 2002 The McGraw-Hill Companies, Inc. All rights reserved. Microsoft Excel 2002 Lesson 1 Introduction.
Chapter 5: Enhancing Classes Presentation slides for Java Software Solutions Foundations of Program Design Second Edition by John Lewis and William Loftus.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Event Driven Programming, The.
Microsoft Office Basics
Ch 3-4: GUI Basics Java Software Solutions Foundations of Program Design Sixth Edition by Lewis & Loftus Coming up: GUI Components.
1 Outline 1 Introduction 2 Overview of Swing Components 3 JLabel 4 Event Handling 5 TextFields 6 How Event Handling Works 7 JButton 8 JCheckBox and JRadioButton.
Graphic User Interface. Graphic User Interface (GUI) Most of us interact with computers using GUIs. GUIs are visual representations of the actions you.
Exploring Windows and Essential Computing Concepts 1 Windows Desktop u Windows Basics u Icon u Start Button u My Computer u Network Neighborhood u Recycle.
Basic Editing Lesson 2.
Creating Graphical User Interfaces (GUI’s) with MATLAB By Jeffrey A. Webb OSU Gateway Coalition Member.
IM103 week 11 Part 2 P532 Case Study part 2: the Airport GUI Learning objectives By the end of this lecture you should be able to:  use the JTabbedPane.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Chapter 15 Creating User.
CHAPTER:07 JAVA IDE PROGRAMMING-II Prepared By Prepared By : VINAY ALEXANDER ( विनय अलेक्सजेंड़र ) PGT(CS),KV JHAGRAKHAND.
Object Oriented Programming.  Interface  Event Handling.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 6 – Graphical User Interfaces Java Foundations: Introduction to Programming.
ELC 310 Day 19. © 2004 Pearson Addison-Wesley. All rights reserved9-2 Agenda Questions? Capstone Proposals Overdue  4 Submitted  3 Accepted, 1 in negotiations.
Lesson: 2 Common Features and Commands After completing this lesson, you will be able to: Identify the main components of the user interface. Identify.
Microsoft Visual Basic 2010 CHAPTER TWO Program and Graphical User Interface Design.
The Excel model for information processing The Excel model is a grid of cells in which items of information are stored and processed. Any information that.
Creating User Interfaces Chapter 13 CSCI CSCI 1302 – Creating User Interfaces2 Outline Introduction Common Features of Swing GUI Components Buttons.
Creating User Interfaces Event-Driven Programming.
Chapter 10 Exceptions 5 TH EDITION Lewis & Loftus java Software Solutions Foundations of Program Design © 2007 Pearson Addison-Wesley. All rights reserved.
Lecture 18: Events; Cool Applets Yoni Fridman 7/30/01 7/30/01.
Oct 091 Example Program DemoInputValidation1.java DemoInputValidation2.java.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Java Software Solutions Foundations of Program Design Sixth Edition by Lewis.
1/18H212Mouse and Timer Events H212 Introduction to Software Systems Honors Lecture #16: Mouse and Timer Events October 26, 2015.
 Figure illustrates a hierarchy containing many event classes from the package java.awt.event.  Used with both AWT and Swing components.  Additional.
Polygons and Polylines © 2004 Pearson Addison-Wesley. All rights reserved 7-1 Arrays can be helpful in graphics processing For example, they can be used.
Today We Will Review: Operating Systems (Windows) (week 3 & 4) Starting up MS Windows Desktop and its contents Functions of the desktop components Brain.
Graphic User Interface. Introduction to Graphics The last few sections of each chapter of the textbook focus on graphics and graphical user interfaces.
Chapter 5: Enhancing Classes Presentation slides for Java Software Solutions Foundations of Program Design Second Edition by John Lewis and William Loftus.
10 Exceptions Software Solutions Lewis & Loftus java 5TH EDITION
Chap 7. Building Java Graphical User Interfaces
Graphical User Interfaces -- Introduction
ITEC220 GUI Lecture – Part 2 References
Presentation transcript:

Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Graphical User Interfaces Revisited Material from Chapters

Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley More about GUIS Specialized containers Dialogs More components More Listeners Advanced Attributes 8-2

Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Specialized Containers JScrollPane JSplitPane We already saw –JTabbedPane (LayoutDemo.java) 8-3

Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 8-4 Scroll Panes A scroll pane is useful for images or information too large to fit in a reasonably-sized area A scroll pane offers a limited view of the component it contains It provides vertical and/or horizontal scroll bars that allow the user to scroll to other areas of the component No event listener is needed for a scroll pane See TransitMap.java TransitMap.java

Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 8-5 Split Panes A split pane ( JSplitPane ) is a container that displays two components separated by a moveable divider bar The two components can be displayed side by side, or one on top of the other Moveable Divider Bar Left Component Right Component Top Component Bottom Component

Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 8-6 Split Panes The orientation of the split pane is set using the HORIZONTAL_SPLIT or VERTICAL_SPLIT constants The divider bar can be set so that it can be fully expanded with one click of the mouse The components can be continuously adjusted as the divider bar is moved, or wait until it stops moving Split panes can be nested

Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Dialogs JOptionPane JFileChooser JColorChooser 8-7

Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 8-8 Dialog Boxes Recall that a dialog box is a small window that "pops up" to interact with the user for a brief, specific purpose The JOptionPane class makes it easy to create dialog boxes for presenting information, confirming an action, or accepting an input value Let's now look at two other classes that let us create specialized dialog boxes

Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 8-9 File Choosers Situations often arise where we want the user to select a file stored on a disk drive, usually so that its contents can be read and processed A file chooser, represented by the JFileChooser class, simplifies this process The user can browse the disk and filter the file types displayed See DisplayFile.java DisplayFile.java

Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 8-10 Color Choosers In many situations we want to allow the user to select a color A color chooser, represented by the JColorChooser class, simplifies this process The user can choose a color from a palette or specify the color using RGB values See DisplayColor.java DisplayColor.java

Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley More Components JList JComboBox JSlider Timer 8-11

Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 8-12 Lists The Swing Jlist class represents a list of items from which the user can choose The contents of a JList object can be specified using an array of objects A JList object generates a list selection event when the current selection changes See PickImage.java PickImage.java See ListPanel.java ListPanel.java

Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 8-13 Lists A JList object can be set so that multiple items can be selected at the same time The list selection mode can be one of three options: –single selection – only one item can be selected at a time –single interval selection – multiple, contiguous items can be selected at a time –multiple interval selection – any combination of items can be selected The list selection mode is defined by a ListSelectionModel object

Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 8-14 Combo Boxes A combo box provides a menu from which the user can choose one of several options The currently selected option is shown in the combo box A combo box shows its options only when the user presses it using the mouse Options can be established using an array of strings or using the addItem method

Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 8-15 Sliders A slider is a GUI component that allows the user to specify a value within a numeric range A slider can be oriented vertically or horizontally and can have optional tick marks and labels The minimum and maximum values for the slider are set using the JSlider constructor A slider produces a change event when the slider is moved, indicating that the slider and the value it represents has changed

Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 8-16 Sliders The following example uses three sliders to change values representing the color components of an RGB value See SlideColor.java SlideColor.java See SlideColorPanel.java SlideColorPanel.java

Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 8-17 The Timer Class

Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 8-18 The Timer Class The Timer class of the javax.swing package is a GUI component, but it has no visual representation A Timer object generates an action event at specified intervals Timers can be used to manage any events that are based on a timed interval, such as an animation To create the illusion of movement, we use a timer to change the scene after an appropriate delay

Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 8-19 The Timer Class The start and stop methods of the Timer class start and stop the timer The delay can be set using the Timer constructor or using the setDelay method See Rebound.java Rebound.java See ReboundPanel.java ReboundPanel.java

Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley New Events Mouse events Key events 8-20

Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 3-21 Mouse Events Events related to the mouse are separated into mouse events and mouse motion events Mouse Events: the mouse pointer is moved off of a componentmouse exited the mouse pointer is moved onto (over) a component mouse entered the mouse button is pressed down and released without moving the mouse in between mouse clicked the mouse button is releasedmouse released the mouse button is pressed downmouse pressed

Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 3-22 Mouse Events Mouse Motion Events: the mouse is moved while the mouse button is pressed down mouse dragged the mouse is movedmouse moved Listeners for mouse events are created using the MouseListener and MouseMotionListener interfaces A MouseEvent object is passed to the appropriate method when a mouse event occurs

Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 3-23 Mouse Events For a given program, we may only care about one or two mouse events To satisfy the implementation of a listener interface, empty methods must be provided for unused events See Dots.java Dots.java See DotsPanel.java DotsPanel.java

Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 3-24 Mouse Events Rubberbanding is the visual effect in which a shape is "stretched" as it is drawn using the mouse The following example continually redraws a line as the mouse is dragged See RubberLines.java RubberLines.java See RubberLinesPanel.java RubberLinesPanel.java

Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 3-25 Key Events A key event is generated when the user types on the keyboard a key on the keyboard is releasedkey released a key on the keyboard is pressed down and releasedkey typed a key on the keyboard is pressed downkey pressed Listeners for key events are created by implementing the KeyListener interface A KeyEvent object is passed to the appropriate method when a key event occurs

Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 3-26 Key Events The component that generates a key event is the one that has the current keyboard focus Constants in the KeyEvent class can be used to determine which key was pressed The following example "moves" an image of an arrow as the user types the keyboard arrow keys See Direction.java Direction.java See DirectionPanel.java DirectionPanel.java

Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 8-27 Event Adapter Classes Inheritance also gives us a alternate technique for creating listener classes We've seen that listener classes can be created by implementing a particular interface, such as MouseListener We can also create a listener class by extending an event adapter class Each listener interface that has more than one method has a corresponding adapter class, such as the MouseAdapter class

Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 8-28 Event Adapter Classes Each adapter class implements the corresponding listener and provides empty method definitions When you derive a listener class from an adapter class, you only need to override the event methods that pertain to the program Empty definitions for unused event methods do not need to be defined because they are provided via inheritance See OffCenter.java OffCenter.java See OffCenterPanel.java OffCenterPanel.java

Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 8-29 Tool Tips and Mnemonics

Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 8-30 Tool Tips A tool tip provides a short pop-up description when the mouse cursor rests momentarily on a component A tool tip is assigned using the setToolTipText method of a Swing component JButton button = new JButton ("Compute"); button.setToolTipText ("Calculate size");

Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 8-31 Mnemonics A mnemonic is a keyboard alternative for pushing a button or selecting a menu option The mnemonic character should be chosen from the component's label, and is underlined The user activates the component by holding down the ALT key and pressing the mnemonic character A mnemonic is established using the setMnemonic method: JButton button = new JButton ("Calculate"); button.setMnemonic ("C");

Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 8-32 Disabled Components Components can be disabled if they should not be used A disabled component is "grayed out" and will not respond to user interaction The status is set using the setEnabled method: JButton button = new JButton (“Do It”); button.setEnabled (false);

Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 8-33 GUI Design The right combination of special features such as tool tips and mnemonics can enhance the usefulness of a GUI See LightBulb.java LightBulb.java See LightBulbPanel.java LightBulbPanel.java See LightBulbControls.java LightBulbControls.java

Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 8-34 The JukeBox Program A combo box generates an action event when the user makes a selection from it See JukeBox.javaJukeBox.java See JukeBoxControls.javaJukeBoxControls.java

Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 3-35 Mouse Events and Key Events