Games3 - Games in Java - Interactivity and user interfaces...

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

View Full Document Right Arrow Icon
Games in Java - Interactivity and user interfaces Programs are in ch03src Wednesday, October 26, 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
First, Java packages and fle organization In the ch03src/src/ directory, there are com/brackeen/javagamebook/graphics com/brackeen/javagamebook/input com/brackeen/javagamebook/test directories This is a package, and is a way o± organizing fles in Java These directories contain code to be reused One-o±± code is in the top src directory package com.brackeen.javagamebook.graphics; import java.awt.Image; import java.util.ArrayList; Wednesday, October 26, 2011
Background image of page 2
Packages allow an additional granularity of protection Access Levels public protected no modifer private Modifer Y Y Y Y Class Y Y Y N Package Y Y N N Subclass Y N N N Wednesday, October 26, 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
Input devices "OfFcial" java libraries support keyboard and mouse inputs There is no ofFcial support for joysticks in Java, but unofFcial packages can be found at sourceforge.net/projects/javajoystick/ Access Levels public protected no modifer private Modifer Y Y Y Y Class Y Y Y N Package Y Y N N Subclass Y N N N Wednesday, October 26, 2011
Background image of page 4
GameCore.java Contains a game core to test additional capabilities The update and init methods don't do much, but will be overridden in other classes to do more useful work. Finally, use Apache Ant to compile this code when necessary. Wednesday, October 26, 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
The AWT Event Model AWT has a thread devoted to dispatching events Receives mouse clicks, key presses, etc. from the OS When AWT receives an event, it looks to see if there is a listener for that event E.g., key press listeners implement the KeyListener interface Wednesday, October 26, 2011
Background image of page 6
AWT event dispatch steps 1. A key is pressed 2. OS sends key event to the Java runtime 3. The Java runtime puts the event in the AWT event queue 4. The AWT event dispatch thread dispatches the event to all KeyListener (s) 5. The KeyListener (s) process the event using user code. Wednesday, October 26, 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
Keyboard Input To capture keyboard events create a KeyListener by instantiating an object from a class that implements the KeyListener interface register the listener A KeyListener requires three methods: keyTyped : not particularly interesting for us keyPressed : called when a key is pressed keyReleased : called when a key is released Wednesday, October 26, 2011
Background image of page 8
The KeyEvent parameter keyPressed , Keyreleased and keyTyped all take a KeyEvent as a parameter Keys are defned in the Form oF KeyEvent constants such as KeyEvent.VK_xxx . A " Q " is KeyEvent.VK_Q Most events can be guessed ( VK_3 , e.g.) but look these up in the Java documentation For the KeyEvent class to be sure Look at the code in KeyTest.java For examples oF listening to key input events.
Background image of page 9

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

View Full DocumentRight Arrow Icon
Image of page 10
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 30

Games3 - Games in Java - Interactivity and user interfaces...

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

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