Java Reference
In-Depth Information
protected boolean
automatic
#
false
;
protected
LocalConsole console;
// reference to the GUI console
public
TankController(String name, String simAdd)
throws
RemoteException {
this
.name
#
name;
try
{
// Registers the controller
Naming.rebind( name
!
"TankController",
this
);
// links the controller to the corresponding pumps
pumpA
#
(PumpInterface)
Naming.lookup("//"
!
simAdd
!
"/"
!
name
!
"PumpA");
pumpB
#
(PumpInterface)
Naming.lookup("//"
!
simAdd
!
"/"
!
name
!
"PumpB");
// links the tank to the controller
tank
#
(TankInterface)
Naming.lookup("//"
!
simAdd
!
"/"
!
name
!
"Tank");
}
catch
(Exception e) {e.printStackTrace();}
}
// opens one of the two pumps and updates the buttons
// of the local GUI console
public void
openPump(String name,
int
percent) {
try
{
if
(name.equals("PumpA")) {
pumpA.setOutputFlow(percent);
console.pumpASlider.setValue(percent);
}
else if
(name.equals("PumpB")) {
pumpB.setOutputFlow(percent);
console.pumpBSlider.setValue(percent);
}
}
catch
(RemoteException re) { re.printStackTrace(); }
}
// implements the control logic
public void
run() {
try
{
// initializes the state according to the initial
// paint level
tankLevel
#
tank.getLevel();
if
(tankLevel <
#
MINIMUM)
tankState
#
EMPTY;
else if
(tankLevel <
#
MEDIUM)
tankState
#
NOTEMPTY;
else if
(tankLevel <
#
MAXIMUM)
tankState
#
NOTFULL;
else
tankState
#
FULL;