Java Reference
In-Depth Information
catch (RemoteException re) {
...
}
In the complete client collaboration developed in Chapter 17, sequence 3 would
involve setting up the client user interface. Since this example has no user inter-
face, we can proceed to sequence 4 where we call initializeSimulation()
and start() . The parameters passed to initializeSimulation() do mat-
ter since they define the spring constant, amplitude, etc. of the simulation we wish
to run. We must follow the convention established on the server for the order of
parameters - i.e. A ,
T , and T max .Wealso defined one additional parameter
that, when set to 1, ends the simulation. So we need an input array of six floats
where the final value is anything except 1:
ω
, K ,
fIndata = new float[] {
fAmplitude, fOmega, fSpringCons, fDeltaT, fMaxTime, 0.f
};
fServer.initializeSimulation (fIndata);
The actual values of the parameters can be hard coded or can come from
command-line parameters passed to main() .
Finally we start the simulation with
fServer.start ();
and begin a polling loop that repeatedly calls fServer.retrieveData()
until a negative time value is seen.
The reader will recall that the collaboration diagram in Chapter 17 took special
pains to start the polling loop before starting the simulation in order to not miss
any simulation results. For this simple example that lacks a user interface, we
have avoided that complexity. Instead we simply start polling immediately after
calling fServer.start() and print the results to standard output.
20.7 Enhanced client using the histogram class
Foranimproved client with a simple user interface, we can use the Histogram
class developed in Chapter 6. Let's make a histogram of the time the oscillating
mass spends in each of a number of bins between
A . Since this is a discreet
simulation, the histogram will not be perfectly smooth, though the smoothness
can be increased by choosing a small
±
T so that all time bins are visited nearly
equally.
Setting up the histogram is easy:
fPositionHist = new Histogram ( " position (x) " , "" , fNumBins,
fAmp, fAmp);
fPositionHPan = new HistPanel (fPositionHist);
Search WWH ::




Custom Search