import java.awt.*; import java.applet.*; import java.util.*; public class benchapplet extends Applet { public TextArea textArea = new TextArea (6, 50); Button compute = new Button("Start Benchmark") ; Button clearbutton = new Button("Clear TextArea") ; public void init () { add(compute); add(clearbutton) ; add(textArea) ; compute.setBackground(Color.red) ; clearbutton.setBackground(Color.green) ; } public void computebench() { this.textArea.append("Starting multiplication of two doubles in 10^4 * 10^4 loops:\n") ; double i,j,k=0; long tcalc; long begin = System.currentTimeMillis() ; for(i=1; i<10000; i++) for(j=1; j<10000; j++) k = i*j ; tcalc = (System.currentTimeMillis() - begin); this.textArea.append("Compute Time (ms): " +tcalc + "\n\n") ; } public boolean action(Event evt, Object arg) { if (evt.target == clearbutton) { this.textArea.setText("") ; return true ; } else if (evt.target == compute) { computebench() ; return true; } else return false; } // end action handler }