Presentation is loading. Please wait.

Presentation is loading. Please wait.

ELC 312 Day 16. © 2004 Pearson Addison-Wesley. All rights reserved Agenda Questions? Capstone Proposals Due Problem set 3 Corrected  Poor performance.

Similar presentations


Presentation on theme: "ELC 312 Day 16. © 2004 Pearson Addison-Wesley. All rights reserved Agenda Questions? Capstone Proposals Due Problem set 3 Corrected  Poor performance."— Presentation transcript:

1 ELC 312 Day 16

2 © 2004 Pearson Addison-Wesley. All rights reserved Agenda Questions? Capstone Proposals Due Problem set 3 Corrected  Poor performance from many  1 A, 1 D, and 2 F’s  Read the UMFK Academic Integrity Policy Exam 2 Corrected  1 A, 1 B and 2 C’s Problem set 4 posted in WebCT  On pages 429-433 complete 7.1, 7.7, 7.12, 7.17, 7.18 and 7.22. On pages 476 and 477 complete 8.1, 8.3, 8.9 and 8.10.  Due November 11 Discussion on Graphics, Mouse events and Keyboard events

3 © 2004 Pearson Addison-Wesley. All rights reserved Outline Declaring and Using Arrays Arrays of Objects Variable Length Parameter Lists Two-Dimensional Arrays The ArrayList Class Polygons and Polylines Mouse Events and Key Events

4 © 2004 Pearson Addison-Wesley. All rights reserved Polygons and Polylines Arrays can be helpful in graphics processing For example, they can be used to store a list of coordinates A polygon is a multisided, closed shape A polyline is similar to a polygon except that its endpoints do not meet, and it cannot be filled See Rocket.java (page 409) Rocket.java See RocketPanel.java (page 410) RocketPanel.java

5 © 2004 Pearson Addison-Wesley. All rights reserved The Polygon Class The Polygon class can also be used to define and draw a polygon It is part of the java.awt package Versions of the overloaded drawPolygon and fillPolygon methods take a single Polygon object as a parameter instead of arrays of coordinates A Polygon object encapsulates the coordinates of the polygon See Rocket2.javaRocket2.java See RocketPanel2.javaRocketPanel2.java

6 © 2004 Pearson Addison-Wesley. All rights reserved Outline Declaring and Using Arrays Arrays of Objects Variable Length Parameter Lists Two-Dimensional Arrays The ArrayList Class Polygons and Polylines Mouse Events and Key Events

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

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

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

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

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

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

13 © 2004 Pearson Addison-Wesley. All rights reserved Summary Chapter 7 has focused on:  array declaration and use  bounds checking and capacity  arrays that store object references  variable length parameter lists  multidimensional arrays  the ArrayList class  polygons and polylines  mouse events and keyboard events

14 © 2004 Pearson Addison-Wesley. All rights reserved Inheritance Inheritance is a fundamental object-oriented design technique used to create and organize reusable classes Chapter 8 focuses on:  deriving new classes from existing classes  the protected modifier  creating class hierarchies  abstract classes  indirect visibility of inherited members  designing for inheritance  the GUI component class hierarchy  extending listener adapter classes  the Timer class


Download ppt "ELC 312 Day 16. © 2004 Pearson Addison-Wesley. All rights reserved Agenda Questions? Capstone Proposals Due Problem set 3 Corrected  Poor performance."

Similar presentations


Ads by Google