If you think the Android project dice-probabilities listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
Java Source Code
package org.kleemann.diceprobabilities;
/*fromwww.java2s.com*/import android.view.View;
import android.widget.Button;
/*
* <p>Provides the behavior for a button that represents the current
* number of dice of a particular type (number of sides) that is
* to be rolled. If number of sides==1 then the die is considerred a
* constant and rendered differently.
*
* <p>When the Pile's count has changed, it calls the passed listener.
*/publicclass CurrentDicePile implements View.OnClickListener {
privateint sides;
protectedint count;
finalprotected Button button;
finalprotected View.OnClickListener changed;
protected CurrentDicePile(int sides, Button button,
View.OnClickListener changed) {
this.sides = sides;
this.count = 0;
this.button = button;
button.setOnClickListener(this);
this.changed = changed;
updateButton();
}
publicstatic CurrentDicePile create(int sides, Button button,
View.OnClickListener changed) {
if (sides == 1) {
returnnew ConstantCurrentDicePile(button, changed);
} else {
returnnew CurrentDicePile(sides, button, changed);
}
}
protectedvoid updateButton() {
button.setText(count + "d" + sides);
button.setVisibility(count == 0 ? View.GONE
: View.VISIBLE);
}
publicint getSides() {
return sides;
}
publicint getCount() {
return count;
}
publicvoid setCount(int count) {
if (count >= 0) {
this.count = count;
updateButton();
changed.onClick(button);
}
}
publicvoid increment() {
setCount(count + 1);
}
publicvoid decrement() {
setCount(count - 1);
}
publicvoid clear() {
setCount(0);
}
@Override
publicvoid onClick(View v) {
decrement();
}
}