10.07.2015 Views

Introduction to Programming Using Java - Department of ...

Introduction to Programming Using Java - Department of ...

Introduction to Programming Using Java - Department of ...

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

viCONTENTS5.5 Inheritance and Polymorphism . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1945.5.1 Extending Existing Classes . . . . . . . . . . . . . . . . . . . . . . . . . . 1945.5.2 Inheritance and Class Hierarchy . . . . . . . . . . . . . . . . . . . . . . . 1965.5.3 Example: Vehicles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1975.5.4 Polymorphism . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2005.5.5 Abstract Classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2025.6 this and super . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2055.6.1 The Special Variable this . . . . . . . . . . . . . . . . . . . . . . . . . . . 2055.6.2 The Special Variable super . . . . . . . . . . . . . . . . . . . . . . . . . . 2065.6.3 Construc<strong>to</strong>rs in Subclasses . . . . . . . . . . . . . . . . . . . . . . . . . . 2085.7 Interfaces, Nested Classes, and Other Details . . . . . . . . . . . . . . . . . . . . 2095.7.1 Interfaces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2095.7.2 Nested Classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2115.7.3 Anonymous Inner Classes . . . . . . . . . . . . . . . . . . . . . . . . . . . 2145.7.4 Mixing Static and Non-static . . . . . . . . . . . . . . . . . . . . . . . . . 2145.7.5 Static Import . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2165.7.6 Enums as Classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 217Exercises for Chapter 5 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 220Quiz on Chapter 5 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2236 <strong>Introduction</strong> <strong>to</strong> GUI <strong>Programming</strong> 2256.1 The Basic GUI Application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2256.1.1 JFrame and JPanel . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2276.1.2 Components and Layout . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2296.1.3 Events and Listeners . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2306.2 Applets and HTML . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2316.2.1 JApplet . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2316.2.2 Reusing Your JPanels . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2336.2.3 Basic HTML . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2356.2.4 Applets on Web Pages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2386.3 Graphics and Painting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2406.3.1 Coordinates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2426.3.2 Colors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2436.3.3 Fonts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2446.3.4 Shapes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2456.3.5 Graphics2D . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2466.3.6 An Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2476.4 Mouse Events . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2516.4.1 Event Handling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2526.4.2 MouseEvent and MouseListener . . . . . . . . . . . . . . . . . . . . . . . . 2536.4.3 Mouse Coordinates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2566.4.4 MouseMotionListeners and Dragging . . . . . . . . . . . . . . . . . . . . . 2586.4.5 Anonymous Event Handlers . . . . . . . . . . . . . . . . . . . . . . . . . . 2626.5 Timer and Keyboard Events . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2646.5.1 Timers and Animation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2646.5.2 Keyboard Events . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2666.5.3 Focus Events . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 269

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!