Skip to content

Instantly share code, notes, and snippets.

@shannah
Created December 6, 2012 22:25
Show Gist options
  • Save shannah/4229057 to your computer and use it in GitHub Desktop.
Save shannah/4229057 to your computer and use it in GitHub Desktop.
Excerpt from Statemachine that responds to button press to perform benchmark.
protected void onMain_BtnTowerOfHanoiAction(Component c, ActionEvent event) {
final Label towerOfHanoiLabel = this.findLblTowerOfHanoi();
towerOfHanoiLabel.setText("Calculating.... Please wait");
if ( isCalculatingHanoi ){
return;
}
isCalculatingHanoi = true;
Thread t = new Thread(new Runnable(){
public void run() {
long start = System.currentTimeMillis();
TowersOfHanoi.move(30, 1, 3);
long end = System.currentTimeMillis();
calculationTime = end - start;
isCalculatingHanoi = false;
Display.getInstance().callSerially(new Runnable(){
public void run() {
towerOfHanoiLabel.setText("Calculation took "+calculationTime+"ms");
}
});
}
});
t.start();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment