File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java Micro Edition and the fly likes How to control the flow of my program? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Mobile » Java Micro Edition
Bookmark "How to control the flow of my program?" Watch "How to control the flow of my program?" New topic
Author

How to control the flow of my program?

Sergio Campos J.
Ranch Hand

Joined: Jun 01, 2009
Posts: 53
In Microedition, I'm using only one Canvas to display graphics
and Keypressed method to read keyboard inputs.

I want to use something like this to control the flow of a game:
But I'm not quite sure about where to put this code to take control of the flow,
since Keypressed & repaint() methods are likely to be outside this control.

Can someone, perhaps, suggest how to manage the flow of the program as I'm trying above?


"There are times when the easy things should be quick and easy" [...] "and worry about the theory later" -Fred Hamilton-
Matthew Cox
Greenhorn

Joined: May 25, 2009
Posts: 29
What you need to do is discern a way to separate your View (the drawing process) from the Model (the game state and logic). Make classes that perform all the logic you want to implement. Then create some shared set of classes where it stores the results of your Model logic.

Then just simply rewrite you View (drawing classes) to access the shared ones. Now you have decoupled the View from the Model. A classic example of this is using a Design Pattern called The Mediator. If you google Mediator Pattern you will find plenty of tutorials on how to adapt your code to this concept. It's fairly straightforward.

A word of caution. After you have had a chance to study the mediator concept ... you'll find it tempting to stuff all your "middle-man" code into ONE class. If you do, you might as well title the class as =P

Make every attempt to divide the in-between logic into multiple mediator classes so that it will be easier for you to debug and make changes that won't cascade (i.e changes that require you to make more changes to existing code that is already working)
Sergio Campos J.
Ranch Hand

Joined: Jun 01, 2009
Posts: 53
Thanks, Mr. Cox!
This seems to be what I need to learn about to step forward.
(I was a little worried about the english barrier to express my doubts)
I'll google Mediator Pattern to find out about this interesting concept.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to control the flow of my program?
 
Similar Threads
Passed SCJP 1.5 with 98%
Is there a restriction about where to use repaint() ?
Complete J2ee Technical Flow
""Do not use exceptions for flow control", huh?
How to crate KeyListener in different Thread?