import java.applet.*; import java.awt.*; import java.awt.event.*; public class PiSimple extends Applet implements ActionListener { TextField tf; double piOverFour; int attempts; Label instructions, colorChange; public void init() { attempts = 0; instructions = new Label("Type number up to a billion and click enter"); add(instructions); tf = new TextField(9); add(tf); tf.addActionListener(this); colorChange = new Label("Color will change when calculation finished"); add(colorChange); } public void paint(Graphics g) { g.drawString("Approximation of pi = " + String.valueOf(4.0*piOverFour), 10 , 100); g.drawString("Actual first dig of pi = 3.14159265358979323846264338....", 10 , 120); } static final int getIntFromString(String s) { s = s.trim(); if (s.equals("") || s == null) return (1); try { return (Integer.valueOf(s).intValue()); } catch (Exception e) { return(1); } } public void actionPerformed (ActionEvent e) { attempts++; int terms = getIntFromString(tf.getText()); if (terms > 1000000000) terms = 1000000000; piOverFour = 0.0; for (int i=0; i