Java For The Fun of It!

skatechildrenΛογισμικό & κατασκευή λογ/κού

3 Νοε 2013 (πριν από 3 χρόνια και 7 μήνες)

48 εμφανίσεις

Session #3322

Java For The Fun of It!

Jack Frosch

Frosch Enterprises, Inc.



Game Development Overview

Air Campaign Commander Demo

How It Was Done



About Me

Why Game Development At All?

Game Development in Java?

Disclaimers & Caveats

Jack Frosch

Founder & President

Frosch Enterprises, Inc.

Just 'cause they're paying us doesn't
mean we can't have fun!

About Me

Why Game Development At All?

Games Are Fundamental to Our

Helps You To Stretch Your Thinking

To Balance Technical and Natural

We All Need A Break

Game Development in Java??

Why Not?

Since JDK 1.02

Java APIs have come a long way

Java VMs have come a long way

Java is showing up everywhere

Hardware has come a long way

Linux + Java = Sony's PS2

Doing Java For The Fun of It!

Disclaimers and Caveats

You know you have to learn to walk before
you can run; this session is to teach you how
to crawl before you learn to walk!

The session is about the basic elements of
game development and doesn't address AI,
player, or network gaming. My game is a
beta of a prototype to an alpha version of a
"real" game!

Legal Disclaimers: Java is a registered
mark of Sun Microsystems; Borland is a
trademark of Borland Inc; IBM is a
registered trade
mark of International Business Machines;
PS2 is a registered trade
mark of Sony Corporation; JavaOne
is a registered trade
mark of Sun Microsystems; JBuilder is a
registered trade
mark of Borland Inc; StartOffice is a registered trade
mark of Sun
Microsystems; Magic Draw UML is a trademark of No Magic, Inc.; Websphere is a registered
trademark of International Business Machines, Inc.; PalmPilot is a registered trade
mark of
Palm, Inc.; these slides are Copyright 2001, Frosch Enterprise, Inc. All other trade
marks and copyrights are
retained by their respective owners.


You Are Here…


Game Development Overview

Air Campaign Commander

How It Was Done


Game Development Overview

General Game Design

The Java Technology Platform

Java APIs Useful For Gaming

Development Tools

General Game Design

Elements of A Game

Some central theme

A Beginning and End

Into A

A Sense of Drama



Fun and/or

A Setting Somewhere Else

Characters or
players, either
human, machine, or

Suspension of Disbelief

Java Technology Platform

Prospects for Game Development


Cell phones & PDAs

Game development exploding on this


end servers

Support for multi
player games on Internet


Desktops & Consoles

Game development is growing

Java APIs Useful For Gaming

Java Swing (included in JDK 1.3)

JavaSound (included in JDK 1.3)

Java2D (included in JDK 1.3)

Collections (included in JDK 1.3)

Java Media Framework (add

Java 3D (add

Others (JAXn, Batik)

Development Tools

Java SDK and add
on APIs are free

Here's What I Used

JDK 1.3.0 / 1.3.1 and JMF 2.1.1 (WPK)

JBuilder 4.0 / 5.0 Enterprise

Sonic Foundry Acid Style 1.0c and Sound
Forge XP 4.5b (for Sound Editing)

No Magic's MagicDraw 4.5 (beta)

MS PowerPoint 2002 (Presentation)

You Are Here…


Game Development Overview

Air Campaign Commander

How It Was Done


Air Campaign Commander

Air Campaign Commander


Design of The Game


Configuring Forces

Game Play Demos

Air Campaign Commander


Capture The Flag

Two combatants wage war using
modern aircraft for attack and
missiles, anti
aircraft artillery, and
radar for defense

As Air Campaign Commander, you
get to acquire and organize assets
into operational units

Air Campaign Commander

Design Overview

Java 1.3 Standard Edition

Swing Based UI

Custom drawing using Java2D

Persistence Using JDataStore

Sound via JavaSound (through JMF)

Media via Java Media Framework 2.1.1

Air Campaign Commander

OO Design Overview

Asset Classes

GUI Classes

Miscellaneous Classes

Collections API

Air Campaign Commander

OO Design: Asset Classes

Air Campaign Commander

OO Design: GUI Classes

Air Campaign Commander

OO Design: Miscellaneous Classes

Air Campaign Commander

Demo: Configuring Forces

Combatant Editor

Asset Editor

Building Units

Deploying Units

Air Campaign Commander

Demo: Game Play

The Ultimate Irony

No Sound Effects, Video, or Music

Sound Effects Only

Background Music Track

You Are Here…


Game Development Overview

Air Campaign Commander

How It Was Done


How It Was Done

An Overview of Key APIs

Java Swing / Java2D

Collections API



Java Media Framework

Noteworthy Core Language Elements

How It Was Done

Java Swing Overview

Classes in javax.swing.** & java.awt.**

The Modified MVC Model



Layout Managers

How It Was Done

Java Swing: Modified MVC

MVC = Model

In this architecture, the presentation layer (View) is
separated from the data (Model). The management of
messages between the two is handled by a Controller

For better performance, Swing uses a Modified MVC

The Swing approach is to put the Controller
functionality in the GUI control, but still keep a separate
Model for storing the data

For Swing developers, the pattern is simple:

Construct and populate the proper model

Construct the GUI component

Add xxxListener(s) to the component

Bind the model to the component

Don't be afraid to subclass models!

How It Was Done

Java Swing: Container Overview

Windows: JFrame and JDialog

The main application frame window is a

The editor windows (AssetEditor,
CombatantEditor, etc.) are modal JDialog


A generic container for holding other
controls and custom drawing. The nesting
of panels is used to support more complex

How It Was Done

Java Swing: Window Tips

All windows use BorderLayout by default

When adding components, don't add directly
to window, but add to contentPane() instead;

Windows have no size by default, so you must
call setSize() to initialize the size of the

Somewhat surprisingly, windows have no
close() method; call win.dispose() to send
WindowEvent to WindowListeners

How It Was Done

Java Swing: JPanel Tips

All JPanels use FlowLayout by default

JPanels are very lightweight, so don't be too
concerned about resource usage when nesting them.
They are NOT derived from awt.Panel, but are
lightweight JComponents

It's easy to create a border around a panel:

Do custom painting using Java 2D in a panel that
subclasses JPanel. You usually only need to override
the paintComponent(Graphics) method. In this
method, you have to redraw all graphics that need to
be redrawn

Components are added directly to the panel

How It Was Done

Java Swing: Control Overview

Swing offers many rich controls for a game
developer; i.e. JButton, JCheckbox,
JComboBox, JLabel, JList, JRadioButton,
JTable, and JTree

JLabel is a wonderfully versatile control. Not
only does it display text, but it is used to
display graphics

Each control can dispatch one or more
message types to one or more listeners. This
allows a great deal of flexibility by promoting
"loose coupling". For instance, all
JComponents support mouse, keyboard, and
focus events, while buttons all support
ActionEvents, and JLists and JTables support
ListSelectionEvents, etc.

How It Was Done

Java Swing: Layout Managers

A Layout Manager enables the proper
presentation of controls in a container when
that container is redrawn

The key concept with most Layout Managers
is understanding how a control's
preferredSize dimensions will be dealt with:
honored, ignored, or resized

BorderLayout, used on windows by default,
divides the container into North, South, East,
West, and Center regions

FlowLayout is used on panels by default

CardLayout is good for stacking panels

XYLayout /null Layout makes prototyping

How It Was Done

Collections API

The Collections API classes are in java.util.*.
Not thread
safe by default, but can be made
so easily

The game uses HashMap (and a derivative),
HashSet, TreeMap, and ArrayList

xxxMap collections have unique keys, but can
have duplicate (and null) values; xxxSet
collections store unique keys and no values

Hashxxx collections are unordered; Treexxx
collections are ordered

ArrayList is a great substitute for Vector

How It Was Done

JDBC & JDataStore

Data in the game is persisted locally in
Borland's JDataStore object database
management system

JBuilder provides a great set of JavaBeans
that hide most of the JDBC complexity. The
game uses the QueryDataSet (like
PowerBuilder DataStore), DataBase,
Connection, and TxManager beans.

Using an OO database generally made
persistence really easy since no OO
mapping was needed, but it often got in the
way during development

Performance was surprisingly good

How It Was Done


The JavaSound API is included in JDK 1.3 and
the Java Media Framework

JavaSound supports playback, recording, and

Since the game uses the JMF anyway, the
separate JavaSound API isn't used

JavaSound class files are in javax.sound.**

Note: When you download JDK 1.3, you won't
get a MIDI SoundBank and need to download
one separately

If Time Allows: JavaSoundDemo

How It Was Done

Java Media Framework

The Java Media Framework API is an add
API and handles time
synchronized rendering
of audio and video

It is an amazingly rich multimedia player
capable of capturing and playing audio and
video, clips and streams

The game uses

Need to set up a ControllerListener to handle
events dispatched by the MediaPlayer

V2.1.1 is much better, but still has quirks.
Recommend playing large files in "static"
situations, not during game play

How It Was Done

Core Language Elements: Random

AirCampCdr.CustomRandom extends
java.util.Random to generate random
numbers, sometimes with bias


Seed set on first call

Math class is final

Probabilities calculated:

Radar Detection Probability

Firing Probability

Hit Probability

Damage Probability

How It Was Done

Core Language Elements: Arrays & Comparable

java.util.Arrays was used to sort Collection
data; i.e. Arrays.sort(arrayList.toArray() )

Objects in ArrayList must implement
java.lang.Comparable interface which
specifies a compareTo method

Classes implement the compareTo method to
specify how object's of that class are to be
compared to other objects

How It Was Done

Core Language Elements: Timer & TimerTask

java.util.Timer and java.util.TimerTask

GameTurn owns a Timer and GameInstance
owns a GameTurn

Subclass TimerTask and code your own run()
method. Then pass that task to one of the
timer.scheduleXXX methods

When the Timer fires at the interval specified,
the TimerTask subclass' run() method is

Bonus Demos

Java 3D

Scalable Vector Graphics (Batik)

You Are Here…


Game Development Overview

Air Campaign Commander

How It Was Done







Acid Style and Sound Forge XP

Magic Draw UML


Movie Trailers:


Thank You

Please fill out the speaker evaluation

You can contact me further at ...