Book contents
- Frontmatter
- Contents
- Preface
- Acknowledgements
- Part I Introduction to Java
- 1 Introduction
- 2 Language basics
- 3 Classes and objects in Java
- 4 More about objects in Java
- 5 Organizing Java files and other practicalities
- 6 Java graphics
- 7 Graphical User Interfaces
- 8 Threads
- 9 Java input/output
- 10 Java utilities
- 11 Image handling and processing
- 12 More techniques and tips
- Part II Java and the network
- Part III Out of the sandbox
- Appendix 1 Language elements
- Appendix 2 Operators
- Appendix 3 Java floating-point
- Index
- References
7 - Graphical User Interfaces
Published online by Cambridge University Press: 08 January 2010
- Frontmatter
- Contents
- Preface
- Acknowledgements
- Part I Introduction to Java
- 1 Introduction
- 2 Language basics
- 3 Classes and objects in Java
- 4 More about objects in Java
- 5 Organizing Java files and other practicalities
- 6 Java graphics
- 7 Graphical User Interfaces
- 8 Threads
- 9 Java input/output
- 10 Java utilities
- 11 Image handling and processing
- 12 More techniques and tips
- Part II Java and the network
- Part III Out of the sandbox
- Appendix 1 Language elements
- Appendix 2 Operators
- Appendix 3 Java floating-point
- Index
- References
Summary
Introduction
In the previous chapter we introduced Java graphics and focused on the display of components, drawings, and images. Here we discuss how to build a graphical display that interacts with the user. A Graphical User Interface (GUI) requires dynamic components like buttons and menus that cause something to happen when the user activates them with the mouse or keyboard. These components generate messages called events that signal what action occurred. We will first look in this chapter at the underlying structure for generating and processing events.
We then introduce several more Swing components such as checkboxes and sliders and present demonstration programs that illustrate how to receive and process the events they generate. We discuss in more detail how components are arranged on the interface with the use of layout managers. For event handling and other tasks, we examine the use of inner classes and adapter classes. After a discussion of frames and menu bars, we demonstrate GUI construction and event techniques with a couple of programs involving histograms.
Events
The graphical user interface (GUI) offers a profoundly different programming environment than the old step-by-step, linear world of a procedural program communicating via a console. In the latter approach, the user simply starts a program and waits for it to churn through its algorithm and eventually reach the end and stop. In the GUI environment, the program instead waits for the user to select some task and then carries out that selected operation.
- Type
- Chapter
- Information
- Publisher: Cambridge University PressPrint publication year: 2005