Presentation is loading. Please wait.

Presentation is loading. Please wait.

Chapter 8: Animation Copyright 2002, Matthew Evett. These slides are based on slides copyrighted by John Lewis and William Loftus, 2002, and used with.

Similar presentations


Presentation on theme: "Chapter 8: Animation Copyright 2002, Matthew Evett. These slides are based on slides copyrighted by John Lewis and William Loftus, 2002, and used with."— Presentation transcript:

1 Chapter 8: Animation Copyright 2002, Matthew Evett. These slides are based on slides copyrighted by John Lewis and William Loftus, 2002, and used with permission. All rights reserved.

2 File Choosers  A GUI-based program sometimes involve the use of external files  A file chooser is a specialized dialog box created using the JFileChooser class  A file chooser allows the user to browse a disk or other storage device to select a file  A text area is similar to a text field, but can contain multiple lines  See DisplayFile.java (page 482) DisplayFile.java

3 The DisplayFile Program

4 Color Choosers  A color chooser is a component that allows a user to specify a color  It is similar to a file chooser in that it displays a special purpose dialog box  It is created using the JColorChooser class  A color can be selected using swatches or RGB values  See DisplayColor.java (page 484) DisplayColor.java

5 The DisplayColor Program

6 Image Icons  An image icon object represents an image  ImageIcon objects use either JPEG or GIF images  They can be used in several situations, such as being displayed in a label  A JLabel can contain a String, and ImageIcon, or both  The orientation of the label's text and image can be set explicitly  See LabelDemo.java (page 487) LabelDemo.java  See LabelPanel.java (page 488) LabelPanel.java

7 The LabelDemo Program

8 Key Events  A key event is generated when a keyboard key is pressed  Constants in the KeyEvent class can be used to determine which key was pressed  The KeyListener interface contains three methods, representing three events: key pressed – a key is pressed key released – a key is released key typed – called when a pressed key produces a key character  See Direction.java (page 490) Direction.java  See DirectionPanel.java (page 491) DirectionPanel.java

9 The Direction Program

10 Animations  An animation is a series of images that gives the appearance of movement  To create the illusion of movement, we use a timer to change the scene after an appropriate delay  The Timer class of the javax.swing package represents a component, even though it has no visual representation  A Timer object generates an action event at specified intervals

11 Animations  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 496) Rebound.java  See ReboundPanel.java (page 497) ReboundPanel.java

12 The Rebound Program

13 Summary  Chapter 8 has focused on: the try-catch statement exception propagation creating and throwing exceptions types of I/O streams Keyboard class processing reading and writing text files object serialization and deserialization more GUI components key events animations


Download ppt "Chapter 8: Animation Copyright 2002, Matthew Evett. These slides are based on slides copyrighted by John Lewis and William Loftus, 2002, and used with."

Similar presentations


Ads by Google