Extending the GUI
WHAT YOU WILL LEARN IN THIS CHAPTER:
- How to create a status bar
- How to create a dialog
- What a modal dialog is and how it differs from a modeless dialog
- How to create a message box dialog
- How you can use components in a dialog to receive input
- What a pop-up menu is
- How you can apply and use transformations to the user coordinate system when drawing on a component
- What context menus are and how you can implement them
In this chapter you investigate how you can improve the graphical user interface (GUI) for Sketcher. After adding a status bar, you create dialogs and explore how you can use them to communicate with the user and manage input. You look at context menus, which are pop-up menus that vary depending on the context in which they are displayed. You use context menus to enhance the functionality of the Sketcher application. All of this gives you a lot more practice in implementing event listeners, and much more besides.
CREATING A STATUS BAR
One limitation of the Sketcher program as it stands is that you have no direct feedback on what the current element type is and what its color is. As a gentle start to this chapter, let’s fix that now. A window status bar at the bottom of an application window is a common and very convenient way of displaying the status of various application parameters, each in its own pane.
There is no Swing class that defines a status bar, so you have to make up your own StatusBar class. Ideally you would design a class ...