Chapter 6
Introduction to GUI Programming
Computer users today expect to interact with their computers using a graphical user interface (GUI). Java can be used to write GUI programs ranging from simple applets which run on a Web page to sophisticated stand-alone applications.
GUI programs differ from traditional "straight-through" programs that you have encountered in the first few chapters of this book. One big difference is that GUI programs are event-driven. That is, user actions such as clicking on a button or pressing a key on the keyboard generate events, and the program must respond to these events as they occur. Event-driven programming builds on all the skills you have learned in the first five chapters of this text. You need to be able to write the subroutines that respond to events. Inside these subroutines, you are doing the kind of programming-in-the-small that was covered in Chapter 2 and Chapter 3.
And of course, objects are everywhere in GUI programming. Events are objects. Colors and fonts are objects. GUI components such as buttons and menus are objects. Events are handled by instance methods contained in objects. In Java, GUI programming is object-oriented programming.
This chapter covers the basics of GUI programming. The discussion will continue in Chapter 12 with more details and with more advanced techniques.
Contents of Chapter 6:
- Section 1: The Basic GUI Application
- Section 2: Applets and HTML
- Section 3: Graphics and Painting
- Section 4: Mouse Events
- Section 5: Timer and Keyboard Events
- Section 6: Basic Components
- Section 7: Basic Layout
- Section 8: Menus and Dialogs
- Programming Exercises
- Quiz on This Chapter