1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
| import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.DataInputStream;
import java.rmi.*;
import java.rmi.server.*;
import java.rmi.registry.*;
import javax.swing.Timer;
public class ServeurThread extends UnicastRemoteObject implements Service, ActionListener{
private Timer timer = new Timer(1000,this);
ClasseTime temps = new ClasseTime();
ServeurThread() throws RemoteException{
super();
}
public static void main ( String args[] ) throws Exception{
ServeurThread svr = new ServeurThread();
DataInputStream saisie = new DataInputStream(System.in);
int port;
if (args.length != 1)
{
System.out.println(" Spécifier le port " );
System.exit(1);
}
else
{
port = Integer.parseInt(args[0]);
Registry registry = LocateRegistry.createRegistry(port);
Naming.bind ("//127.0.0.1:"+port+"/Service", svr);
System.out.println (" Attente d'appel ...");
}
}
public void actionPerformed(ActionEvent Evt){
if (Evt.getSource().equals(timer))
modifCpt();
}
public void modifCpt(){
temps.modifier("+");
}
public void demarrer() throws RemoteException{
timer.start();
System.out.println("Demarrer");
}
public void arreter() throws RemoteException{
timer.stop();
System.out.println("Arreter");
}
public String recupererCpt() throws RemoteException{
System.out.println("Recuperation, temps:"+temps.recupererTemps());
return temps.recupererTemps();
}
} |