Java 1.4 Game Programming (Wordware Game and Graphics Library)

There are a whole host of parameters that we may supply in the constructor for our JFrame derivative TemplateGraphicsApplication. The following method calls are a few of the most common that we are interested in at this early stage. We can set up the constructor as follows.

public TemplateGraphicsApplication() { super("Template Graphics Application"); setDefaultCloseOperation(EXIT_ON_CLOSE); setResizable(false); getContentPane().setLayout(null); setBounds(0, 0, 400, 400); }

Part of what we have added we have already seen in the previous chapter. The call to the super class constructor simply allows us to define the window title that will be displayed in its top border. We need to specify the default close operation because a window when closed, by default, is merely hidden (we will look at this in a moment). We also set our window so that it is not resizable because, in most cases, if you create a 2D game, it is more than likely you are working to a fixed pixel resolution, as 2D scaling can be expensive as well as cause unexpected distortion in your graphics.

Категории