Planetalia - Java Training

Training and Consulting

Home

Tutorial - Writing a Space Invaders game in Java

  Previous Page - Introduction Current Page - 01 - The First Window   Next Page - Closing the window
  Return to the index of free Java tutorials  

The First Window

(c) Alexander Hristov
English Version proofreading and corrections : Jeff Lunt

Of course, the first step in our Java program will be the main class with the entry point. Our first version will create a Swing window ( JFrame ) and we will - rather arbitrarily - decide that the window size will be 800 x 600. The particular size is irrelevant, and it is a good habit to declare all dimensions - and all literals - as constants, just in case we decide to change them later.

The source code for this first step should be fairly easy to understand:


1     package version01;
2     /**
3      * Curso B?sico de desarrollo de Juegos en Java - Invaders
4      * 
5      * (c) 2004 Planetalia S.L. - Todos los derechos reservados. Prohibida su reproducci?n
6      * 
7      * http://www.planetalia.com
8      * 
9      */
10    
11    
12    import javax.swing.JFrame;
13    
14    public class Invaders  {
15      public static final int WIDTH = 800;
16      public static final int HEIGHT = 600;
17      
18      public Invaders() {
19        JFrame ventana = new JFrame("Invaders");
20        ventana.setBounds(0,0,WIDTH,HEIGHT);
21        ventana.setVisible(true);
22        
23      }
24      
25      public static void main(String[] args) {
26        Invaders inv = new Invaders();
27      }
28    
29    }
30    

Where does this get us? A window so simple that it doesn't even terminate the program when closed:

Tutorial Space Invaders en Java



Do you want to be notified when new tutorials or lessons are published? Press here


Full list of Java source files for this step

Invaders.java      

Full list of resources

bicho.gif bicho0.gif bicho1.gif bicho2.gif
bombD.gif bombDL.gif bombDR.gif bombL.gif
bombR.gif bombU.gif bombUL.gif bombUR.gif
disparo.gif disparo0.gif disparo1.gif disparo2.gif
explosion.wav misil.gif missile.wav musica.wav
nave.gif oceano.gif photon.wav test.gif
Thumbs.db      

  Previous Page - Introduction Current Page - 01 - The First Window   Next Page - Closing the window
  Return to the index of free Java tutorials  

(c) 2004 Planetalia S.L. All rights reserved. Unauthorized reproduction and/or mirroring is not permitted