Template Graphics Windowed Application

To begin with, we will take a look at a basic template windowed application, where we create a window and look at some of the important features involved in the graphical side of the window. We will begin with the example class TemplateGraphicsApplication, building this example up piece by piece, explaining as we go. Let's start with a template class consisting of the constructor and paint method and of course the main method. (Note that the initial base class when run will not create our window and will exit the program straight away.)

import java.awt.*; import javax.swing.*;     public class TemplateGraphicsApplication extends JFrame {     public TemplateGraphicsApplication()     {         // code to go here     }       public void paint(Graphics g)     {         // code to go here     }       public static void main(String[] args)     {     } }

The code so far indicates that we have a main class called TemplateGraphicsApplication that extends the JFrame class (we saw about extending the JFrame class in the previous chapter) and includes a default constructor and a method called paint that takes a parameter object reference of type Graphics. The paint method that we declare here is the same as the very important paint method belonging to the JFrame class. Here, we provide our own version of the paint method, overriding the one we would have inherited from the JFrame class. In order to understand the means by which the paint method works, you must first understand about the Event Dispatch Thread that we touched upon briefly in Chapter 7.



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