Presentation is loading. Please wait.

Presentation is loading. Please wait.

ITEC220 GUI Lecture – Part 2 References  Java Software Solutions,” by Lewis & Loftus  Chapter 7  Chapter 8  Chapter 9  Java Foundations-Introduction.

Similar presentations


Presentation on theme: "ITEC220 GUI Lecture – Part 2 References  Java Software Solutions,” by Lewis & Loftus  Chapter 7  Chapter 8  Chapter 9  Java Foundations-Introduction."— Presentation transcript:

1 ITEC220 GUI Lecture – Part 2 References  Java Software Solutions,” by Lewis & Loftus  Chapter 7  Chapter 8  Chapter 9  Java Foundations-Introduction to Program Design & Data Structures,” by Lewis, DePasquale, and Chase  Chapter 6

2 Chapter 7 Arrays References Java Software Solutions,” by Lewis & Loftus  Chapter 7  Chapter 8  Chapter 9 Java Foundations-Introduction to Program Design & Data Structures,” by Lewis, DePasquale, and Chase  Chapter 6

3 © 2004 Pearson Addison-Wesley. All rights reserved2-3 Outline Mouse Events and Key Events

4 © 2004 Pearson Addison-Wesley. All rights reserved2-4 Mouse Events Events related to the mouse are separated into mouse events and mouse motion events Mouse Events: mouse pressedthe mouse button is pressed down mouse releasedthe mouse button is released mouse clickedthe mouse button is pressed down and released without moving the mouse in between mouse enteredthe mouse pointer is moved onto (over) a component mouse exitedthe mouse pointer is moved off of a component

5 © 2004 Pearson Addison-Wesley. All rights reserved2-5 Mouse Events Mouse Motion Events: mouse movedthe mouse is moved mouse draggedthe mouse is moved while the mouse button is pressed down 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

6 © 2004 Pearson Addison-Wesley. All rights reserved2-6 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 (page 413) Dots.java See DotsPanel.java (page 414) DotsPanel.java

7 © 2004 Pearson Addison-Wesley. All rights reserved2-7 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 (page 417) RubberLines.java See RubberLinesPanel.java (page 418) RubberLinesPanel.java

8 © 2004 Pearson Addison-Wesley. All rights reserved2-8 Key Events A key event is generated when the user types on the keyboard key presseda key on the keyboard is pressed down key releaseda key on the keyboard is released key typeda key on the keyboard is pressed down and released 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

9 © 2004 Pearson Addison-Wesley. All rights reserved2-9 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 (page 421) Direction.java See DirectionPanel.java (page 422) DirectionPanel.java

10 Chapter 8 Inheritance References Java Software Solutions,” by Lewis & Loftus  Chapter 7  Chapter 8  Chapter 9 Java Foundations-Introduction to Program Design & Data Structures,” by Lewis, DePasquale, and Chase  Chapter 6

11 © 2004 Pearson Addison-Wesley. All rights reserved2-11 Outline The Timer Class

12 © 2004 Pearson Addison-Wesley. All rights reserved2-12 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

13 © 2004 Pearson Addison-Wesley. All rights reserved2-13 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 (page 471) Rebound.java See ReboundPanel.java (page 472) ReboundPanel.java

14 Chapter 9 Polymorphism References Java Software Solutions,” by Lewis & Loftus  Chapter 7  Chapter 8  Chapter 9 Java Foundations-Introduction to Program Design & Data Structures,” by Lewis, DePasquale, and Chase  Chapter 6

15 © 2004 Pearson Addison-Wesley. All rights reserved2-15 Outline File Choosers and Color Choosers

16 © 2004 Pearson Addison-Wesley. All rights reserved2-16 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

17 © 2004 Pearson Addison-Wesley. All rights reserved2-17 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 (page 516) DisplayFile.java

18 © 2004 Pearson Addison-Wesley. All rights reserved2-18 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 (page 519) DisplayColor.java

19 Chapter 6 Graphical User Interfaces References Java Software Solutions,” by Lewis & Loftus  Chapter 7  Chapter 8  Chapter 9 Java Foundations-Introduction to Program Design & Data Structures,” by Lewis, DePasquale, and Chase  Chapter 6

20 © 2004 Pearson Addison-Wesley. All rights reserved – Tool Tips A tool tip is a short line of text that appears over a component when the mouse cursor is rested momentarily on top of the component Tool tips usually inform the user about the component Tool tips can be assigned by using the setToolTipText method of a component JButton button = new Button (“Compute”); button.setToolTipText (“Calculates the area under the curve”);

21 © 2004 Pearson Addison-Wesley. All rights reserved – Mnemonics (1) A mnemonic is a character that allows the user to push a button or make a menu choice using the keyboard in addition to the mouse For example, when a mnemonic has been defined for a button, the user can hold down the Alt key and press the mnemonic character to activate (depress) the button Mnemonic character ‘f’ set for the Off button

22 © 2004 Pearson Addison-Wesley. All rights reserved – Mnemonics (2) We set the mnemonic for a component using the setMnemonic method of the component Once set, a character in the label will be underlined to indicate that it can be used as a shortcut JButton button = new Button (“Off”); button.setMnemonic (“f”); Mnemonic character ‘f’ set for the Off button


Download ppt "ITEC220 GUI Lecture – Part 2 References  Java Software Solutions,” by Lewis & Loftus  Chapter 7  Chapter 8  Chapter 9  Java Foundations-Introduction."

Similar presentations


Ads by Google