Game Development Reference
In-Depth Information
grp = 0.5*x/Math.sqrt(diffusivity*time);
erf = getErrorFunction(grp);
temperature = boundaryT + (initialT-boundaryT)*erf;
return temperature;
}
The GUI elements of the Gas Tank Simulator are implemented in the GasTankSimulator
class. The class is a bit different than the GUI classes previously presented in this topic, so we'll
spend a little time talking about it. The first part of the class is similar to the others. A number
of GUI components are created to accept user input and display the results. A GasTank object
is declared that will represent the gas tank. A Timer object is used to control the execution of
the game. When the Start button is pressed, the actionPerformed method declared in the
GasTankSimulator method is called. The first thing the method does is to extract the user inputs
for the tank thickness, tank material, and flame temperature from the text fields.
public void actionPerformed(ActionEvent event) {
// Get some initial quantities from the text fields.
double flameTemp = Double.parseDouble(flameTempTextField.getText());
double thickness = Double.parseDouble(thicknessTextField.getText());
The value for diffusivity is set to the value for aluminum and the initial temperature of the
tank is set to be 300 K . A GasTank object is created based on the input quantities.
// Set the initial temperature.
double initialT = 300.0;
// Set the diffusivity according to the material selected.
double diffusivity;
String material = (String)materialComboBox.getSelectedItem();
if ( material.equals("Aluminum") ) {
diffusivity = 9.975e-5;
}
else {
diffusivity = 6.6e-7; // concrete
}
// Create a GasTank object.
tank = new GasTank(thickness, diffusivity, initialT, flameTemp);
The value shown in the outer wall temperature text field is set to the flame temperature,
the GUI display is updated, and the start method is called on the Timer object to start the
simulation.
// Set the display for the outer wall temperature text field.
outerTempTextField.setText(""+flameTemp);
Search WWH ::




Custom Search