[ First Section | Previous Chapter | Next Chapter | Main Index ]

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 sophisticated GUI programs.

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 methods that respond to events. Inside those methods, 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 13 with more details and with more advanced techniques.

This edition of this textbook covers GUI programming using the Swing GUI toolkit, which is a standard part of Java and has been included in the JDK since Java 2. An alternative edition covers JavaFX instead of Swing. That edition can be found at https://math.hws.edu/javanotes9. The only really significant differences between the two editions are in this chapter and in Chapter 13.


Contents of Chapter 6:


[ First Section | Previous Chapter | Next Chapter | Main Index ]