Disabling the Layout Manager

In Java all component containers have a default layout manager. A layout manager is an object that is used to handle the layout of components added to a container; for example, it can be used to calculate the positions and dimensions of a number of buttons that you add to a container automatically and position them in a desired pattern, with little work on your part once they are set up. We discussed components and containers in the last chapter, but just to remind you, speaking in terms of our current example, the content pane of the JFrame is a container that can hold other components, which themselves can be containers, building up what is effectively a containment hierarchy.

For example, adding a JPanel object to the content pane of the JFrame means that the content pane of the JFrame would contain a JPanel, and in turn the JPanel could contain, say, a button object and so on. We will look at the JPanel a little later in this chapter when we look at adding components. We disable the layout manager because a layout manager is used to control the position of your components in the container to which the layout manager belongs. This means that the layout manager will handle repositioning your components when, say, your window is resized. It is very useful for GUI-based applications with coordinated buttons but not really for games where, in simple terms, you want to have complete control over where you draw everything. Note that in many examples in this chapter, we may not set the layout manager to null and leave it as the default one. The layout manager is only important when adding components to containers and not when drawing your own graphics, so it is quite irrelevant for this section. But we thought we'd mention it all the same.



Java 1.4 Game Programming
Java 1.4 Game Programming (Wordware Game and Graphics Library)
ISBN: 1556229631
EAN: 2147483647
Year: 2003
Pages: 237

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net