Graphics Programs Reference
In-Depth Information
Listing 6-5.
TANK FENCE GAME 1/src/com/apress/android/tankfencegame1/
Main.java
public void getDeviceWidth() {
DisplayMetrics dm = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(dm);
int width = dm.widthPixels;
int height = dm.heightPixels;
if (width > height) {
_width = width;
} else {
_width = height;
}
}
6-6
) sets the click listeners for the up and down buttons. These buttons will be used
for forward-backward movement of the tank. The extent of this movement (or the
number of steps moved) is stored inside a counter. Similar use of a counter has been
Listing 6-6.
TANK FENCE GAME 1/src/com/apress/android/tankfencegame1/
Main.java
public void setUpDownClickListeners() {
Button buttonUp, buttonDown;
buttonUp = (Button) findViewById(R.id.up);
buttonDown = (Button) findViewById(R.id.down);
buttonUp.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
synchronized (this) {
Counter.getUpDownNextValue();
}
}
});
buttonDown.setOnClickListener(new OnClickListener() {
Search WWH ::
Custom Search