Java Reference
In-Depth Information
private Sketcher theApp;
There are new methods in the Sketcher class that return a reference to the application window, the
model, and the view, so any of these are accessible from anywhere that a reference to the application
object is available.
After creating the model and view objects, we register the view as an observer for the model to enable
the model to notify the view when it changes. We then add the view to the content pane of the window
object, which is the main application window. Since it is added in the center using the BorderLayout
manager for the content pane, it will occupy all the remaining space in the pane.
Now that we know roughly the direction in which we are heading, let's move on down the road.
Coordinate Systems in Components
In Chapter 15, we saw how your computer screen has a coordinate system that is used to define the
position and size of a window. We also saw how we can add components to a container with their
position established by a layout manager. This coordinate system is analogous to the screen coordinate
system. The origin is at the top-left corner of the container, with the positive x -axis running horizontally
from left to right, and the positive y -axis running from top to bottom. The positions of buttons in a
JWindow or a JFrame object are specified as a pair of ( x , y ) pixel coordinates, relative to the origin at
the top-left corner of the container object on the screen. Below you can see the coordinate system for
the Sketcher application window.
Of course, the layered pane for the window object will have its own coordinate system with the origin in
the top-left corner of the pane, and this is used to position the menu and the content pane. The content
pane will have its own coordinate system too that will be used to position the components it contains.
It's not just containers and windows that have their own coordinate system: each JButton object also
has its own system, as do JToolBar objects. In fact, every component has its own coordinate system.
Search WWH ::




Custom Search