Free Web Hosting Provider - Web Hosting - E-commerce - High Speed Internet - Free Web Page
Search the Web

/* 5K Mile Pace Calculator
JDK 1.1 version.
Written by Allen W. Murphy 8/2/1999
http://gocreek.8k.com
coach@gocreek.8k.com
*/

import java.awt.*;
import java.awt.event.*;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.applet.Applet;
import java.lang.*;

public class CalculatePace extends Applet implements ActionListener {

// Objects
TextField textField;
Label label1;
Label label2;
Button b1;

public void init() {

textField = new TextField(12);
b1 = new Button();
label1 = new Label();
label2 = new Label();

label1.setText("5K Pace Calculator");
textField.setText("Enter 5k time here");
b1.setLabel("Calculate Pace");
b1.setActionCommand("button_hit");
label2.setText("Pace per mile is:");

add(label1);
add(textField);
add(b1);
add(label2);

b1.addActionListener(this);
textField.addActionListener(this);

}

public void paint(Graphics g){

Dimension d = getSize();
g.drawRect(0,0,d.width-1,d.height-1);

}

public void actionPerformed(ActionEvent evt) {

// Variables
String myTime = textField.getText();
String myPace;
double minutes;
double seconds;
double temp;
double Pace;
long Pmin;
double Psec;

if(evt.getActionCommand() == "button_hit") {

minutes=Integer.parseInt(myTime.substring(0,2));
seconds=Integer.parseInt(myTime.substring(3,5)) + Integer.parseInt(myTime.substring(6))/10;

temp = minutes * 60 + seconds;
Pace = temp/3.107;
Pmin = Math.round(Math.floor(Pace/60));
Psec = Pace - Pmin*60;
Psec = Math.floor(Psec*10)/10;

if (Psec >= 10){

myPace = Pmin + ":" + Psec;

}
else {

myPace = Pmin + ":0" + Psec;

}

label2.setText(myPace);

}

}

}