Java Reference
In-Depth Information
velocityDisplay.setText (milliToStr (velocity));
fuelDisplay.setText (milliToStr (fuel < 0 ? 0 : fuel));
thrust = fuel <= 0 ? 0 : thrustSlider.getValue();
}
}
The constructor just sets up the user interface by adding the controls and labels to the application frame:
public PdaLander() {
Panel intermediate = new Panel (new BorderLayout());
Panel controlPanel = new Panel (new GridLayout (0, 2));
controlPanel.add(new Label ("Height:"), Label.LEFT);
controlPanel.add(heightDisplay);
controlPanel.add(new Label ("Velocity:"));
controlPanel.add(velocityDisplay);
controlPanel.add(new Label ("Fuel:"));
controlPanel.add(fuelDisplay);
controlPanel.add(new Label ("Thrust:"));
controlPanel.add(thrustSlider);
intermediate.add(controlPanel, BorderLayout.NORTH);
frame.add(intermediate, BorderLayout.CENTER);
frame.addWindowListener(new WindowAdapter() {
public void windowClosing (WindowEvent ev) {
notifyDestroyed();
}
} );
frame.pack();
}
When the application is brought on the screen and not yet running, the simulation thread is started:
public void startApp() {
frame.show();
if (simulation == null) {
simulation = new Simulation();
simulation.start();
}
}
When the application is paused by the Application Management System (AMS), we do nothing. This
behavior could be improved by suspending the ScreenManager thread.
public void pauseApp() {
}
When the application is terminated, the height is set to a negative value in order to make sure that the
simulation thread terminates immediately. Then the frame is disposed:
public void destroyApp (boolean unconditional) {
height = -100000000;
frame.dispose();
}
}
Search WWH ::




Custom Search