Game Development Reference
In-Depth Information
The
actionPerformed
method that is called when the Fire button is pressed extracts the
input values from all of the text fields including the input values for the x- and y-components
of wind velocity. A
WindProjectile
object is created and initialized with the input values. The
start
method is called to begin the simulation.
// The actionPerformed() method is called when
// the Fire button is pressed.
public void actionPerformed(ActionEvent event) {
// Get the initial quantities from the text fields.
double vx0 = Double.parseDouble(vxTextField.getText());
double vy0 = Double.parseDouble(vyTextField.getText());
double vz0 = Double.parseDouble(vzTextField.getText());
double mass = Double.parseDouble(massTextField.getText());
double area = Double.parseDouble(areaTextField.getText());
double cd = Double.parseDouble(cdTextField.getText());
double density = Double.parseDouble(densityTextField.getText());
distanceToHole = Double.parseDouble(distanceTextField.getText());
double windVx = Double.parseDouble(windVxTextField.getText());
double windVy = Double.parseDouble(windVyTextField.getText());
// Create a WindProjectile object representing the golf ball.
golfball = new WindProjectile(0.0, 0.0, 0.0, vx0, vy0, vz0,
0.0, mass, area, density, cd, windVx, windVy);
// Update the display.
updateDisplay();
// Start the box sliding using a Timer object
// to slow down the action.
gameTimer.start();
}
The
actionPerformed
method that the
Timer
object calls in the
GolfGame3
class is exactly
the same as the
actionPerformed
method that the
Timer
called in the
GolfGame2
class (which
was exactly the same as the
actionPerformed
method in the
GolfGame
class).