0
Real World
Technologies:
NetBeans GUI Builder,
JRuby, JavaFX, and
Java ME

developers.sun.com/students/courses



        ...
Topics
• Introduction to “Real World Technologies: NetBeans
  GUI Builder, JRuby, JavaFX, and Java ME – Earn a
  Certifica...
Real World Technologies 5-hour
Online Course
• You can take it anytime – it is free!
• http://developers.sun.com/students/...
NetBeans GUI
Builder



               4
NetBeans GUI Builder (Matisse)
• Issues with building GUI without Matisse
  >   Complexity with Swing APIs
  >   Resizing ...
Free Design
• You can build your forms by simply putting
  components where you want them as though you
  were using absol...
Automatic Component Positioning
• As you add components to a form, the GUI Builder
  provides visual feedback that assists...
Visual Feedback
• The GUI Builder also provides visual feedback
  regarding component anchoring and chaining
  relationshi...
NetBeans GUI Builder
Demo: These Are The
Exercises You Will Do
as Part of the Course
Demo 1: Building a Contact Editor




                                    10
Demo 2: Adding Event Handlers




                                11
JRuby &
JRuby on Rails



                 12
Topics
•   What is and Why JRuby?
•   What is “JRuby on Rails”?
•   “Ruby on Rails” Principles
•   Why “Ruby on Rails”?
• ...
What is and Why JRuby?
Open source
        Java
implementation of the
        Ruby
      language
                        15
What Is JRuby?
•   Started in 2002
•   Java platform implementation of Ruby language
•   Open source, many active contribu...
JRuby: Java Technology Integration
• Script Java
  > Power of Java technology with the Syntax of Ruby


      require 'jav...
Why JRuby?
• JRuby over Ruby
  >   Strong likelihood we will be faster soon
  >   Better scalability with native threading...
What is “JRuby on Rails”?
What Is “Ruby on Rails”?
• A full-stack MVC web development framework
• Open source (MIT), many contributors
• Written in ...
“Ruby on Rails”
Principles
“Ruby on Rails” Principles
• Convention over configuration
  > Why punish the common cases?
  > Encourages standard practi...
Why “Ruby on Rails”?
• Greatly simplified web development
  > Instant applications: working code in minutes
  > “Less Rail...
Why “JRuby on Rails”
over “Ruby on Rails”?
• Deployment to Java application servers
• Java technology production environme...
“JRuby on Rails”: Java EE Platform
• Pool database connections
• Access any Java Naming and Directory Interface™
  (J.N.D....
“JRuby on Rails”: Deployment
Platforms
• Mongrel
  > Built-in container
• Warfile deployment to:
  > GlassFish™ V2
  > Gla...
JRuby on Rails: Futures
• Improve Java EE platform support for Rails
  > Rubify Java EE platform APIs
  > Create Rails plu...
JRuby on Rails
Demo: These Are The
Exercises You Will Do
as Part of the Course
Demo 1: Building WebLog Webapp




                                 29
Demo 2: Building Flickr Webapp




                                 30
JavaFX
Programming



              31
Topics
•   What is and Why JavaFX?
•   JavaFX Product family and Architecture
•   JavaFX Script
•   JavaFX Script examples...
What is and Why
JavaFX?




                  33
Market Trends
• Personal & mobile computing are blurring
  > Handsets becoming more advanced
  > Higher-speed IP Networks
...
The GUI Quagmire
• Java Swing and 2D APIs are very powerful and yet
  > Why does it take a long time to write GUI programs...
Why yet another scriting language
for Java, JavaFX Script?
• Language for Spicying up Java GUI Programing
  easier
• Build...
Expanding the Community
                                Professionals
    Programming (Java) skills




                  ...
JavaFX
Product Family &
Architecture



                   38
JavaFX Product Family
• Announced at JavaONE 2007
• Leverages the Java platform's write-once-run-
  anywhere portability, ...
JavaFX: An Architecture that Scales
 The Big
 Picture
              Home          JavaFX
 Devices                         ...
JavaFX Workflow
Visual                   Content developer
                                                               ...
What is
JavaFX Script?




                 42
What is JavaFX Script?
• Formerly known as F3 (Form Follows Function) of
  Chirstopher Oliver from Sun Microsystems
  > ht...
What is JavaFX Script?
• Extensive widget library encompassing Swing
  components and Java2D objects
• Easily create and c...
JavaFX Script – A Simple Comparison
In JavaFX Script                                      In Java
                        ...
JavaFX Script Examples:
Hello World

                          46
Example : Hello world in Java FX

import javafx.ui.*;


Frame {
    title: quot;Hello World JavaFXquot;
    width: 200
   ...
Example : Hello world in Swing
import javax.swing.*;


public class HelloWorldSwing {
  public static void main(String[] a...
Data Binding




               49
Data Binding in JavaFX
• Cause and Effect—Responding to change
• The JavaFX bind operator—Allows dynamic content to be
  e...
Example: Dynamic Behavior
class HelloWorldModel {
     attribute saying: String;
}
var model = HelloWorldModel {
     sayi...
Java 2D




          52
Java 2D API
• To match the designs of UI designers requires using Java
  2D API
• But Java 2D API doesn’t have composition...
Java ME
Programming



              54
Topics
•   What is and Why Java ME?
•   Java ME architecture
•   NetBeans Mobility Pack Features
•   Game development




...
What is and Why
Java ME?




                  56
Why Develop Mobility Applications?

• “Application at your fingertips”
• Personal
  > One of 4 things you always carry wit...
The Java™ Platforms



Java Technology   Java Technology   Workgroup   High-End
Enabled Devices   Enabled Desktop    Serve...
Java on Mobile Devices




     Mobile Service Architecture (MSA) provides
a complete platform for mobile application deve...
Java ME Application Market

                             $3B




   $3 Billion Java
 Mobile Game Market
                  ...
Java ME
Architecture




               61
Java Platforms

 Optional
Packages
                                   Java Platform,
              Optional
              ...
Java ME CLDC Stack
• Connected Limited Device Configuration (CLDC)
  > For devices with limited memory and processing powe...
Java ME CLDC Stack (2)
• Multitude of optional JSRs: Media, Bluetooth,
  Messaging, Location, SIP, and many more
• More JS...
Java ME Evolution in Wireless
MIDP → JTWI → MSA (Mobile Service Architecture)

                                         We...
Compelling Feature Phone Platform:
MSA (JSR 248)
 Comms        Graphics          Security & Application  Personal
        ...
NetBeans Mobility
Pack




                    67
Mobility Pack
             A full IDE built around Sun JavaTM
             Wireless Toolkit
●   Open,                     ...
Visual Designer




                  69
SVG
• SVG = Scalable Vector Graphics
• Automatically adjusts to screen size
• Two roles
  > Graphical designers create ima...
NetBeans 6.0 Mobility New Feature
• New game builder
  > Easier to create mobile games with the Mobility Pack's
    visual...
Game Development




                   72
Development of Java
Technology-Based Games
         • JSR 184 (3D Graphics)
           • 3D world creation and manipulatio...
Examples of 2D Games




                       74
Core Game API Class Hierarchy




                                75
Game Canvas
• GameCanvas specifically for developing game
  display
  > Class extends GameCanvas to use it
• Subclass of C...
GameCanvas Example –
Main Game Loop
01 //main game loop
02 while (true) {
03        //Poll key press
04        int key = g...
Elements in a Game
Background          Sprite
                             • Background
                               > C...
Creating a TiledLayer
       tileHeight




                    TiledLayer background = new TiledLayer(
                  ...
Creating the Background


 5 5 5 5 5 5 5 5   5 5 5 5




        // Draw the water
        for (int x = 0; x < 12; x++)
  ...
Creating Animated Tile




//Indicate the tile to be animated
int animatedTile = backgroud.createAnimatedTile(5);




//Sw...
Creating Sprites
Loading is similar to TiledLayer




                      Calling nextFrame() will
                     ...
Changing the Frame Sequence


               sprite.setFrameSequence
               (new int[]
                  {0, 1, 2,...
Reference Pixel on Sprites

     Default
 reference pixel
     at (0, 0)




                             84
Real World
Technologies:
NetBeans GUI Builder,
JRuby, JavaFX, and
Java ME


                        85
Upcoming SlideShare
Loading in...5
×

Real World Technologies

3,455

Published on

Real World Technologies:
NetBeans GUI Builder, JRuby, JavaFX, and
Java ME. A brief introduction on each one.

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
3,455
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
89
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Transcript of "Real World Technologies"

  1. 1. Real World Technologies: NetBeans GUI Builder, JRuby, JavaFX, and Java ME developers.sun.com/students/courses 1
  2. 2. Topics • Introduction to “Real World Technologies: NetBeans GUI Builder, JRuby, JavaFX, and Java ME – Earn a Certificate” 5-hour online course • NetBeans GUI Builder • JRuby & JRuby on Rails • Java FX Programming • Java ME Programming 2
  3. 3. Real World Technologies 5-hour Online Course • You can take it anytime – it is free! • http://developers.sun.com/students/courses • You get exposed to exciting and leading-edge real- life technologies • You do the hands-on lab and homework • If you submit all 4 homeworks, you will receive PDF version of certificate • You can participate in the course forum 3
  4. 4. NetBeans GUI Builder 4
  5. 5. NetBeans GUI Builder (Matisse) • Issues with building GUI without Matisse > Complexity with Swing APIs > Resizing and Alignment are hard > Locale handling > Behave differently over different OS platforms • Matisse handles all these for you! > Guidelines provided at design time to help with placing and sizing controls > Adjustments made at runtime for user's look & feel and locale 5
  6. 6. Free Design • You can build your forms by simply putting components where you want them as though you were using absolute positioning • The GUI Builder figures out which layout attributes are required and then generates the code for you automatically. > You need not concern yourself with insets, anchors, fills, and so forth. 6
  7. 7. Automatic Component Positioning • As you add components to a form, the GUI Builder provides visual feedback that assists in positioning components based on your operating system's look and feel. • The GUI Builder provides helpful inline hints and other visual feedback regarding where components should be placed on your form, automatically snapping components into position along guidelines. 7
  8. 8. Visual Feedback • The GUI Builder also provides visual feedback regarding component anchoring and chaining relationships. • These indicators enable you to quickly identify the various positioning relationships and component pinning behavior that affect the way your GUI will both appear and behave at runtime. > This speeds the GUI design process, enabling you to quickly create professional-looking visual interfaces that work. 8
  9. 9. NetBeans GUI Builder Demo: These Are The Exercises You Will Do as Part of the Course
  10. 10. Demo 1: Building a Contact Editor 10
  11. 11. Demo 2: Adding Event Handlers 11
  12. 12. JRuby & JRuby on Rails 12
  13. 13. Topics • What is and Why JRuby? • What is “JRuby on Rails”? • “Ruby on Rails” Principles • Why “Ruby on Rails”? • Why “JRuby on Rails”? 13
  14. 14. What is and Why JRuby?
  15. 15. Open source Java implementation of the Ruby language 15
  16. 16. What Is JRuby? • Started in 2002 • Java platform implementation of Ruby language • Open source, many active contributors • Aiming for compatibility with current Ruby version • Integrates with Java technology > Call to Ruby from Java technology via Java Specification Request (JSR) 223, BSF, Spring > Use Java class files from Ruby (e.g., Script Java) • Growing set of external projects based on JRuby > JRuby-extras (GoldSpike, ActiveRecord-JDBC,…) 16
  17. 17. JRuby: Java Technology Integration • Script Java > Power of Java technology with the Syntax of Ruby require 'java' list = java.util.ArrayList.new list << 1 list << 3 list << 2 list.sort 17
  18. 18. Why JRuby? • JRuby over Ruby > Strong likelihood we will be faster soon > Better scalability with native threading > Native unicode support > Compilation > Integration with Java libraries > Easier path to getting Ruby in the enterprise • JRuby over Java technology > Language features > Blocks, modules, metaprogramming, dynamic-typing > Ruby applications/libraries > Rails, Rspec, Rake, Raven, other R’s 18
  19. 19. What is “JRuby on Rails”?
  20. 20. What Is “Ruby on Rails”? • A full-stack MVC web development framework • Open source (MIT), many contributors • Written in Ruby • First released in 2004 by David Heinemeier Hansson • Gaining popularity > Ruby and Rails book sales are outselling Perl book sales 20
  21. 21. “Ruby on Rails” Principles
  22. 22. “Ruby on Rails” Principles • Convention over configuration > Why punish the common cases? > Encourages standard practices > Everything simpler and smaller • Don’t Repeat Yourself (DRY) > Framework written around minimizing repetition > Repetitive code harmful to adaptability • Agile development environment > No recompile, deploy, restart cycles > Simple tools to generate code quickly > Testing built into the framework 22
  23. 23. Why “Ruby on Rails”? • Greatly simplified web development > Instant applications: working code in minutes > “Less Rails code than Java application configuration” • Growing community of developers • Makes small apps trivial to create • Ruby is an excellent language 23
  24. 24. Why “JRuby on Rails” over “Ruby on Rails”? • Deployment to Java application servers • Java technology production environments pervasive > Easier to switch framework vs. whole architecture > Lower barrier to entry • Broader, more scalable database support • Integration with Java technology libraries, legacy services • No need to leave Java technology servers, libraries, reliability 24
  25. 25. “JRuby on Rails”: Java EE Platform • Pool database connections • Access any Java Naming and Directory Interface™ (J.N.D.I.) API resource • Access any Java EE platform TLA: > Java Persistence API (JPA) > Java Management Extensions (JMX™) > Enterprise JavaBeans™ (EJB™) > Java Message Service (JMS) API > SOAP/WSDL/SOA 25
  26. 26. “JRuby on Rails”: Deployment Platforms • Mongrel > Built-in container • Warfile deployment to: > GlassFish™ V2 > GlassFish™ V3 > Servlet-based app server 26
  27. 27. JRuby on Rails: Futures • Improve Java EE platform support for Rails > Rubify Java EE platform APIs > Create Rails plug-ins to make installable units • Use Java technology native equivalents > Unicode support > XML support • Port Ruby native libraries > RMagick 27
  28. 28. JRuby on Rails Demo: These Are The Exercises You Will Do as Part of the Course
  29. 29. Demo 1: Building WebLog Webapp 29
  30. 30. Demo 2: Building Flickr Webapp 30
  31. 31. JavaFX Programming 31
  32. 32. Topics • What is and Why JavaFX? • JavaFX Product family and Architecture • JavaFX Script • JavaFX Script examples 32
  33. 33. What is and Why JavaFX? 33
  34. 34. Market Trends • Personal & mobile computing are blurring > Handsets becoming more advanced > Higher-speed IP Networks • Ecosystem shifting to “platforms” > Full application environment including middleware, user experience, etc. > Reduce development costs and improves device consistency • Software stacks largely proprietary > Industry looking for an Open alternative 34
  35. 35. The GUI Quagmire • Java Swing and 2D APIs are very powerful and yet > Why does it take a long time to write GUI programs? > How can we avoid the “Ugly Java technology GUI” stereotype? > Why do Flash programs look different than Java programs? > Why does it seem easier to write web apps than Swing programs? > How can I avoid having an enormous mass of listener patterns? 35
  36. 36. Why yet another scriting language for Java, JavaFX Script? • Language for Spicying up Java GUI Programing easier • Building and running of media/content- rich Java clients application much easier • More productive by making Swing and Java 2D™ API accessible to a much the script programmer • Simple Accessing of Java Objects • Serve as persistence format for a new class of tools targeted at non programmers like designers and end users 36
  37. 37. Expanding the Community Professionals Programming (Java) skills Community size Java developers Script programmers Visual designers Hobbyist 37
  38. 38. JavaFX Product Family & Architecture 38
  39. 39. JavaFX Product Family • Announced at JavaONE 2007 • Leverages the Java platform's write-once-run- anywhere portability, application security model, ubiquitous distribution and enterprise connectivity • Initially comprised of: JavaFX Script > Highly productive scripting language for content developers to create rich media and interactive content JavaFX Mobile > Mobile software stack available via OEM license to carriers and handset manufacturers seeking a branded relationship with consumers 39
  40. 40. JavaFX: An Architecture that Scales The Big Picture Home JavaFX Devices Desktop Content Authoring Tools Entertainment Mobile Interactive JavaFX Script Content JavaFX Framework 2D/3D AGUI PBP SVG/MSA CLDC CDC CDC SE 40
  41. 41. JavaFX Workflow Visual Content developer Java FX Mobile Designer App Binary JavaFX Mobile g in ag ck Java FX TV JavaFX Script code Pa App Binary Visu ng ck agi JavaFX TV Pa al A sse n ts tio Pa la pi ck m ag Co Java FX Source ing Application Java FX Desktop App Binary JavaFX Tools JavaFX Desktop / Consumer JRE 41
  42. 42. What is JavaFX Script? 42
  43. 43. What is JavaFX Script? • Formerly known as F3 (Form Follows Function) of Chirstopher Oliver from Sun Microsystems > http://blogs.sun.com/chrisoliver/category/JavaFX • Java Scripting Language > Object-oriented > Static typing + type inference > Declarative Syntax > Automatic Data Binding > Mixed functional/procedural evaluation model 43
  44. 44. What is JavaFX Script? • Extensive widget library encompassing Swing components and Java2D objects • Easily create and configure individual components • Work with all major IDEs • Statically typed - retains same code structuring, reuse, and encapsulation features of Java • Capable of supporting GUIs of any size or complexity • Makes it easier to use Swing • Rich Internet Applications (RIA) 44
  45. 45. JavaFX Script – A Simple Comparison In JavaFX Script In Java Main guitar class  picks.opacity = [0, .01 .. 1 ] dur 1000 linear        guitarAnimationThread = new StringOpThread();        ......        ......        if (guitarAnimationThread != null) {           guitarAnimationThread.run();        } In Java        ......... (SwingLabs Timing StringOpThread class        ........... Framework)     public void run() { public void class Guitar {            opacityBegin = 0.01;        opacityEnd = 1.0;     private GuitarPick pick = ...;            opacityIncreStep = 0.02;     public Guitar() {            opacitySleep = 2;         pick.setOpacity(.5f);         for(currOpacity = opacityBegin;         Animator a =               currOpacity < opacityEnd;     PropertySetter.createAnimator(                 currOpacity+=opacityIncreStep) { 300, pick, quot;opacityquot;, .5f, 1.0f);           setPickOpacity();           repaint();         MouseTrigger.addTrigger(pick, a,           try { MouseTriggerEvent.ENTER, true);             thread.sleep(opacitySleep);     }           } catch (InterruptedException e) { } } 45
  46. 46. JavaFX Script Examples: Hello World 46
  47. 47. Example : Hello world in Java FX import javafx.ui.*; Frame { title: quot;Hello World JavaFXquot; width: 200 height: 50 content: Label { text: quot;Hello Worldquot; } visible: true } 47
  48. 48. Example : Hello world in Swing import javax.swing.*; public class HelloWorldSwing { public static void main(String[] args) { JFrame frame = new Jframe(quot;HelloWorld Swingquot;); final JLabel label = new JLabel(quot;Hello Worldquot;); frame.getContentPane().add(label); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.pack(); frame.setVisible(true); } 48
  49. 49. Data Binding 49
  50. 50. Data Binding in JavaFX • Cause and Effect—Responding to change • The JavaFX bind operator—Allows dynamic content to be expressed declaratively • Dependency-based evaluation of any expression • Automated by the system—Rather than manually wired by the programmer • You just declare dependencies and the JavaFX runtime takes care of performing updates when things change • Eliminates listener patterns 50
  51. 51. Example: Dynamic Behavior class HelloWorldModel { attribute saying: String; } var model = HelloWorldModel { saying: quot;Hello Worldquot; }; var win = Frame { title: bind quot;{model.saying} JavaFXquot; width: 200 content: TextField { value: bind model.saying } visible: true }; 51
  52. 52. Java 2D 52
  53. 53. Java 2D API • To match the designs of UI designers requires using Java 2D API • But Java 2D API doesn’t have compositional behavior > The barrier to entry for many Java code programmers is too high (i.e., other than Romain Guy) • In addition to Swing Components, JavaFX includes SVG- like interfaces to Java 2D API as first-class elements which can be composed together into higher-level components • JavaFX allows declarative expression of this composition 53
  54. 54. Java ME Programming 54
  55. 55. Topics • What is and Why Java ME? • Java ME architecture • NetBeans Mobility Pack Features • Game development 55
  56. 56. What is and Why Java ME? 56
  57. 57. Why Develop Mobility Applications? • “Application at your fingertips” • Personal > One of 4 things you always carry with you (keys, wallet, watch, handphone) • Powerful, feature rich, programmable and royalty free > Games in particular • Anyone commuting will have 30mins to kill > Capture audience • It's not really that difficult 57
  58. 58. The Java™ Platforms Java Technology Java Technology Workgroup High-End Enabled Devices Enabled Desktop Server Server 58
  59. 59. Java on Mobile Devices Mobile Service Architecture (MSA) provides a complete platform for mobile application development 59
  60. 60. Java ME Application Market $3B $3 Billion Java Mobile Game Market 60
  61. 61. Java ME Architecture 61
  62. 62. Java Platforms Optional Packages Java Platform, Optional Micro Edition (Java ME) Packages Optional Packages Personal Advanced Profile GUI Java (PP) (AGUI) Optional Packages Platform, Java PersonalBasis Profile (PBP) Enterprise Platform, JTWI/MSA Mobile Foundation Profile (FP) Edition Standard Information Device Profile (Java EE) Edition Connected (MIDP) Connected (Java SE) Device Limited Device Configuration Java Configuration (CDC) Card (CLDC) 62
  63. 63. Java ME CLDC Stack • Connected Limited Device Configuration (CLDC) > For devices with limited memory and processing power > KVM (Kilo VM) Virtual Machine especially designed for devices with limited computing power and resources • Mobile Information Device Profile (MIDP) > Defines application model, OTA (over-the-air) installation, basic UI model and widgets, media capabilities, basic Game API, RMS (record management system), connectivity, security model 63
  64. 64. Java ME CLDC Stack (2) • Multitude of optional JSRs: Media, Bluetooth, Messaging, Location, SIP, and many more • More JSRs are in the pipeline • “Umbrella” JSRs > Define a complete platform from existing JSRs • Example > JSR 185 (Java Technology for Wireless Industry/JTWI) > JSR 248 (Mobile Services Architecture/MSA) 64
  65. 65. Java ME Evolution in Wireless MIDP → JTWI → MSA (Mobile Service Architecture) We are here MSA CDC (2007-08) Capability MSA Device CLDC JTWI (2006) CLDC MIDP (2003) CLDC (2001) 65
  66. 66. Compelling Feature Phone Platform: MSA (JSR 248) Comms Graphics Security & Application Personal Commerce Connectivity Information JSR 82 JSR 226 Bluetooth 2D Scalable Vector Graphics JSR 180 JSR 184 SIP 3D Graphics JSR 205 JSR 234 JSR 229 JSR 211 JSR 179 MMS Mobile-media Content Payment Location Messaging Supplement Handler JSR 120 JSR 135 JSR 177 JSR 172 JSR 75 SMS Security & Mobile Media Web Services PIM & File Messaging Trust Services Application JSR 185 JSR 118 JSR 238 JTWI MIDP 2.0 I18N Environment Virtual JSR 139 Conditional APIs Machine CLDC 1.1 JTWI APIs 66
  67. 67. NetBeans Mobility Pack 67
  68. 68. Mobility Pack A full IDE built around Sun JavaTM Wireless Toolkit ● Open, ● Java ME integrated I D Platform development environment E emulation ● Build, test, SD ● Device deploy rich K agnostic applications ● Provides ● Accelerate additional application utilities for time-to- application market support ● Visual, drag- ● Over 2,000,000 combined n-drop downloads authoring ● Industry voted awards 68
  69. 69. Visual Designer 69
  70. 70. SVG • SVG = Scalable Vector Graphics • Automatically adjusts to screen size • Two roles > Graphical designers create images > Developers add business logic • Visual designer for SVG > SVG Menu, SVG Splash Screen, SVG Wait Screen, SVG Image, ... 70
  71. 71. NetBeans 6.0 Mobility New Feature • New game builder > Easier to create mobile games with the Mobility Pack's visual editing support for the MIDP 2.0 Game API > API supports animated sprites and the ability to arrange tiled layers into scenes • New Integrated UI for CLDC/MIDP and CDC development • New Visual Mobile Designer • Design analysis • New components for Flow Control 71
  72. 72. Game Development 72
  73. 73. Development of Java Technology-Based Games • JSR 184 (3D Graphics) • 3D world creation and manipulation • JSR 135 (Mobile Media) • Sounds • JSR 82 (Bluetooth) • P2P gaming • JSR 180 (SIP) • P2P over the network • JSR 229 (Payment) • Payment of new levels 73
  74. 74. Examples of 2D Games 74
  75. 75. Core Game API Class Hierarchy 75
  76. 76. Game Canvas • GameCanvas specifically for developing game display > Class extends GameCanvas to use it • Subclass of Canvas but provides the following improvements > Off-screen buffering > Keypad polling > Access to Graphics object > Do not need to override paint(Graphics) method • Behavior can be set to be backward compatible with Canvas 76
  77. 77. GameCanvas Example – Main Game Loop 01 //main game loop 02 while (true) { 03 //Poll key press 04 int key = getK eyStates(); 05 if ((key & G ameC anvas.L EFT_PR ESSED) != 0) { 06 //update game objects 07 } 08 if ((key & G ameC anvas.UP_PR ESSED) != 0) { 09 //update game objects 10 } 11 //Get off-screen graphics object 12 G raphics g = getG raphics(); 13 //update game screen 14 ... 15 //update the 'dirty' portion to the screen 16 flushG raphics(x, y, dirtyW idth, dirtyHeight); 17 } 77
  78. 78. Elements in a Game Background Sprite • Background > Composable from basic elements > Static and animated objects • Background layers > Different layers > Layer management • Sprites > Transformation > Collision detection Viewport 78
  79. 79. Creating a TiledLayer tileHeight TiledLayer background = new TiledLayer( 50, 50, image, tileWidth, tileHeight) tileWidth 79
  80. 80. Creating the Background 5 5 5 5 5 5 5 5 5 5 5 5 // Draw the water for (int x = 0; x < 12; x++) background.setCell(x, y, 5); Tile index 80
  81. 81. Creating Animated Tile //Indicate the tile to be animated int animatedTile = backgroud.createAnimatedTile(5); //Switch the animated tile backgroud.setAnimateTile(animatedTile, 6); 81
  82. 82. Creating Sprites Loading is similar to TiledLayer Calling nextFrame() will display the next frame 82
  83. 83. Changing the Frame Sequence sprite.setFrameSequence (new int[] {0, 1, 2, ... 1, 1}); sprite.nextFrame(); 83
  84. 84. Reference Pixel on Sprites Default reference pixel at (0, 0) 84
  85. 85. Real World Technologies: NetBeans GUI Builder, JRuby, JavaFX, and Java ME 85
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×