Java Reference
In-Depth Information
int getScrY() {
int scrH = getSize().height;
return scrH - (int) (height * scrH / START_HEIGHT);
}
public void check() {
if (thrust != oldThrust || oldY != getScrY())
repaint();
}
}
The second improvement of our new
PdaLander
version is an automatic adoption to the screen size
ratio. Because the graphical display takes some additional space to the right of the controls, the labels
are automatically displayed above the controls instead of to the left if the height of the screen is greater
than the width:
public PdaLander2() {
Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
boolean vertical = d.height > d.width;
Panel intermediate = new Panel (new BorderLayout());
Panel controlPanel = new Panel (new GridLayout (0, vertical ?
1 : 2));
int align = vertical ? Label.LEFT : Label.RIGHT;
controlPanel.add(new Label ("Height:", align));
controlPanel.add(heightDisplay);
controlPanel.add(new Label ("Velocity:", align));
controlPanel.add(velocityDisplay);
controlPanel.add(new Label ("Fuel:", align));
controlPanel.add(fuelDisplay);
controlPanel.add(new Label ("Thrust:", align));
controlPanel.add(thrustSlider);
intermediate.add(controlPanel, BorderLayout.NORTH);
frame.add(intermediate, BorderLayout.WEST);
frame.add(externalView, BorderLayout.CENTER);
frame.addWindowListener(new WindowAdapter() {
public void windowClosing (WindowEvent ev) {
notifyDestroyed();
}
} );
frame.pack();
}
Listing 4.12
shows the complete source code of the enhanced
PdaLander
example and
Figure 4.12
shows a screenshot of the
PdaLander
running on a Palm Pilot.
Figure 4.12. The
PdaLander2
application running on a Palm Pilot.
Search WWH ::
Custom Search