Java Reference
In-Depth Information
Similar to the other examples, there is much room for your own improvements. For example, the
display of a crashed lander could be designed differently from a successful landing. A more
sophisticated extension would be to allow vertical movements and to add some kind of terrain structure.
Another possible improvement would be to add a double buffered display, eliminating any screen
flickering.
Listing 4.12
PdaLander2.java
import java.awt.*;
import java.awt.event.*;
import javax.microedition.midlet.*;
public class PdaLander2 extends MIDlet {
Frame frame = new Frame ("PDAlander");
Simulation simulation;
ScreenManager screenManager = new ScreenManager();
Label velocityDisplay = new Label();
Label heightDisplay = new Label();
Label fuelDisplay = new Label();
Scrollbar thrustSlider =
new Scrollbar (Scrollbar.HORIZONTAL, 0, 0, 0, 100);
ExternalView externalView = new ExternalView();
static final long START_HEIGHT = 1000000;
static final long GRAVITY = 1620; // mm/s2
static final long ACCELERATION = 2*GRAVITY;
static final long MAX_VELOCITY = 1000;
long velocity = 0; // mm/s
long height = START_HEIGHT; // mm
long fuel = 100000; // ms
long thrust = 0;
class ExternalView extends Canvas {
int oldY;
long oldThrust;
public void paint (Graphics g) {
Search WWH ::
Custom Search