Training and Consulting | ||
| Home |
| 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 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:
|
||||||||
Do you want to be notified when new tutorials or lessons are published? Press here
| Invaders.java |
| 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