Games2 - Games in Java Monday, October 24, 2011 For...

Info iconThis preview shows pages 1–9. Sign up to view the full content.

View Full Document Right Arrow Icon
Games in Java Monday, October 24, 2011
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
For programs go to http://www.brackeen.com/javagamebook/ You will need apache ant to build some of these -- download 1.8.2 it at http://ant.apache.org/ Monday, October 24, 2011
Background image of page 2
Three ways to do Java games 1. Applet games -- run as a Java applet within a browser Easiest for the user to run Security restrictions on applets prevent full use and destruction of the computer (i.e. cannot write to Fles, limited internet access, etc.) 2. Windowed games -- full Java programs, escape from applet security restrictions, but have UI elements that are distracting (buttons, frames) 3. ±ull screen game - what we will discuss, but can do 2 for project Monday, October 24, 2011
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Display properties Screen layouts Pixel color and bit depth Refresh rate (0,0) (m,0) (m,n) (0,n) Monday, October 24, 2011
Background image of page 4
JFrame window = new Jframe(); DisplayMode displayMode = new DisplayMode(800,600,16,75); // get the GraphicsDevice GraphicsEnvironment environment = GraphicsEnvironment.getLocalGraphicsEnvironment(); Graphics device = environment.getDefaultScreenDevice( ); // use the JFrame as the full screen window device .setFullScreenWindow( window ); // change the display mode device .setDisplayMode( displayMode ); // to switch back to the previous display mode: device.setFullScreenWindow(null); This is not complete code Some systems won't allow you to change the display mode. If so, setDisplayMode( ) throws an IllegalArgumentException . Monday, October 24, 2011
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
JFrame window = new Jframe(); DisplayMode displayMode = new DisplayMode(800,600,16,75); // get the GraphicsDevice GraphicsEnvironment environment = GraphicsEnvironment.getLocalGraphicsEnvironment(); Graphics device = environment.getDefaultScreenDevice( ); // use the JFrame as the full screen window device.setFullScreenWindow(window); // change the display mode device.setDisplayMode(displayMode); // to switch back to the previous display mode: device.setFullScreenWindow(null); This is a window object this is the display characteristics this connects your program to the physical display and allows you to change its characteristics Connects the JFrame to the display device Sets the device characteristics Monday, October 24, 2011
Background image of page 6
import java.awt.*; import javax.swing.JFrame; public class FullScreenTest extends JFrame { public static void main(String[] args) { DisplayMode displayMode; if (args.length == 3 ) { displayMode = new DisplayMode( Integer.parseInt(args[ 0 ]), Integer.parseInt(args[ 1 ]), Integer.parseInt(args[ 2 ]), DisplayMode.REFRESH_RATE_UNKNOWN); } else { displayMode = new DisplayMode( 800 , 600 , 16 , DisplayMode.REFRESH_RATE_UNKNOWN); } FullScreenTest test = new FullScreenTest(); test.run(displayMode); } private static final long DEMO_TIME = 5000 ; public void run(DisplayMode displayMode) { setBackground(Color.blue); setForeground(Color.white); setFont( new Font( "Dialog" , 0 , 24 )); SimpleScreenManager screen = new SimpleScreenManager(); try { screen.setFullScreen(displayMode, this ); try { Thread.sleep(DEMO_TIME); } catch (InterruptedException ex) { } } finally { screen.restoreScreen(); } } public void paint(Graphics g) { g.drawString( "Hello World!" , 20 , 50 ); } } FullScreenTest.java from Brackeen's site Monday, October 24, 2011
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
public void run(DisplayMode displayMode) { setBackground(Color.blue); setForeground(Color.white);
Background image of page 8
Image of page 9
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 44

Games2 - Games in Java Monday, October 24, 2011 For...

This preview shows document pages 1 - 9. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online