V

Annexes



  1. Les techniques de programmation
  2. [A] Client - Serveur

    Ce programme démontre le fonctionnement du serveur décrit dans la documentation. Le serveur attent le client, puis lance un thread dédié à ce client. Le thread contient une socket permetant l'envoie de message entre le serveur et le client.

    L'exemple montre l'implémentation du serveur et du client. Le serveur peut reçecoir un String, le transforme en majuscule puis le renvoie au client

    1. Le serveur
    2.  //***************************************************************************// Program: @(#)Server.java
      // @author: Jean-Marc@Autexier
      //
      // @version: 2.07.1997
      // @param: args[0] port-number
      // purpose: La classe "Server" crée un serveur en écoute sur le port
      // passé en paramètre. Lorsqu'une requette est signalisé sur le port, un thread
      // est démaré avec la socket du Client.
      //
      // Usage: Server [Numero_de_port]
      // 
      //***************************************************************************
      import java.io.* ;
      import java.net.* ;
      import java.lang.* ;
       
      public class Server
      {
         public static void main(String args[])
         {
            ServerSocket SS = null ;
            Socket S = null ;
       
            // Le premier arhument doit contenir le numéro du port du Serveur
            if (args.length != 1 )
            {
               System.err.println("Usage : Server [Numero_du_port]") ;
               System.exit(1) ;
            }
                      
            try
            {
      	   // Initialisation du serveur
               SS = new ServerSocket( Integer.parseInt(args[0]) ) ;
               if ( SS != null)
               {
                  // le serveur est démaré et attend une requette
      		System.out.println("Server running on port " + args[0] ) ;
                  while (( S = SS.accept()) != null )	// Attendre une requette
                     ( new SocketThread(S)).start() ;	// Démarer le thread pour le client
               }
            }
            catch(IOException e)        
            {
               System.out.println(e) ;
            }
         }
      }
       
      //**********************************************************************
      // Classe SocketThread
      // Description : La classe SocketTread est un Thread et peu donc etre 
      // éxécuté parallèlement au autres threads. Son constructeur initalise
      // une socket passée en paramètre. Cet socket permet de communiquer avec
      // le client en utilisant cette socket.
      // Le Stream "DataInputStream permet de lire de la socket, le Stream
      // PrintStream crit sur la socket.
      //**********************************************************************
       
      class SocketThread extends Thread
      {
         protected Socket socket = null ;
         
         // Constructeur à partir d'une socket
         public SocketThread(Socket socket)
         {
            this.socket = socket ;
         }
       
         public void run()
         {
            String Line = null ;      // Ligne servant a lire et écrire sur la socket
       
            try
            {
      	// In JDK1.1, the PrintStream and the DataInputStream are deprecated.
      	// They are replaced by the classes PrintWriter and BufferedReader
      	// out : Stream pour lire sur la socket
      	// in  : Stream pour crir sur la socket
      	PrintWriter out = new PrintWriter(socket.getOutputStream()) ;
      	// Il faut transformer DataInputStream de getInputStream en InputStreamReader
      	// pour permetre de crer un BufferedReader
      	BufferedReader in = new BufferedReader(new
       							InputStreamReader(socket.getInputStream())) ;
      	// On peut lire sur la socket par la mthode readline de BufferedReader
      	// On peut crire sur la socket par la mthode println de PrintWriter
               
      	// Pour controller le serveur, on affiche chaque connection
      	System.out.print("New client : " ) ;
      	System.out.println(socket.toString() ) ;
               
               
               //*****************************************************************
               // Ici tourne le programme du Client         
               //*****************************************************************
                 
               // ex. de programme : conversion d'un String en majuscule
               
      	while (( Line = in.readLine() ) != null )
      	{
      		System.out.println("Message recu : " + Line ) ;
      		out.println(Line.toUpperCase() ) ;  // renvoi du String en majuscule
      	}  
                        
      	//****************************************************************
      	// Fin du programme Client
      	//****************************************************************
               
      	// Déconnexion du serveur
      	System.out.print("Client beendet: ");
      	System.out.println(socket.toString() );
      	socket.close() ;
      	}
      	catch(IOException e)
      	{
      		System.out.println(e) ;
      	}
          }
      }
      

    3. Le client
    4. Le client affiche une interface permetant de saisir un string. Lorsqu'on appui sur le bouton "Envoyer", le string est envoyé au serveur. Le client attend la réponse et l'affiche dans un champ de l'interface.

      import java.net.* ;
      import java.io.* ;
      import java.awt.* ;
      import java.applet.Applet ;
       
      public class Client extends Applet
      {
      	int instanceNumber = 1 ;
      	Label label = null ;
      	TextField  portField ;
       
      	public void init()
      	{ 
      		setLayout(new GridLayout(3,1,10,10)) ;
       
      		Panel tPanel = new Panel() ;
      		tPanel.setLayout(new GridLayout(1,2,10,10)) ;
      		tPanel.add(new Label("Port number :")) ;
      		tPanel.add(portField = new TextField(10)) ;
      		add(tPanel) ;
      		add(new Button("Client starten") ) ;
      		add(label = new Label("", label.CENTER)) ;
      		validate() ;
      	}
       
      	public boolean action(Event event, Object what)
      	{
      		if (event.target instanceof Button)
      		{
      			try
      			{
      				// Le client crée la connexion au serveur
      				int port = Integer.parseInt(portField.getText()) ;
      				label.setText("Client wird gestartet") ;
      				URL hostURL = getDocumentBase() ;
      				ClientWindow window = new ClientWindow(hostURL.getHost(),port) ;
       
      				if (instanceNumber == 1 )
      					window.setTitle("Client") ;
      				else
      					window.setTitle("Client : " + instanceNumber) ;
       
      				instanceNumber++ ;
      				window.resize(400,200) ;
      				window.show() ;
      				window.resize(400,200) ; // nescessaire pour netscape
       
      				label.setText("") ;
      			}
      			catch(NumberFormatException e )
      			{
      				label.setText("Port angeben") ;
      			}
      		}
      		return false ;
      	}
      }
       
       
      class ClientWindow extends Frame
      {
      	Socket socket = null ;
      	Button transferButton ;
      	Button endButton ;
       
      	DataInputStream in      = null ;
      	PrintStream out         = null ;
      	TextField sendField     = null ;
      	TextField reciveField   = null ;
      	Label label1 ;
      	Label label2 ;
       
      	public ClientWindow(String Host, int Port) 
      	{
      		setLayout(new GridLayout(5,1,10,10)) ;
       
      		add((label1 = new Label("Host: " + Host))) ;
      		add((label2 = new Label("Port: " + String.valueOf(Port)))) ;
       
      		Panel Panel1 = new Panel() ;
      		Panel1.setLayout(new GridLayout(1,2,10,10)) ;
      		Panel1.add(new Label("Texte envoyé :")) ;
      		Panel1.add(sendField = new TextField(30)) ;
       
      		Panel Panel2 = new Panel() ;
      		Panel2.setLayout(new GridLayout(1,2,10,10)) ;
      		Panel2.add(new Label("Texte reçu :")) ;
      		Panel2.add(reciveField = new TextField(30)) ;
       
      		Panel Panel3 = new Panel() ;
      		Panel3.setLayout(new GridLayout(1,2,10,10)) ;
      		Panel3.add(( transferButton = new Button("Envoyer") ) );
      		Panel3.add(( endButton = new Button("Terminer client") ) );
       
      		add(Panel1) ;
      		add(Panel2) ;
      		add(Panel3) ;
       
      		if ( socket == null ) 
      		{
      			try
      			{
      				socket = new Socket(Host, Port) ;
      				in = new DataInputStream(socket.getInputStream()) ;
      				out = new PrintStream(socket.getOutputStream()) ;
      			}
      			catch(UnknownHostException e )
      			{
      				label1.setText("Server non reconnu") ;
      				label2.setText("") ;
      			}
      			catch(IOException e )
      			{
      				label1.setText("Erreur de transmission") ;
      				label2.setText("") ;
      			}
      		}
      	}
       
      	public boolean handleEvent(Event evt) 
      	{
      		if ("Envoyer".equals(evt.arg))
      		{
      			if (socket != null )
      			{
      				try
      				{
      					// Le texte est envoyé 
      					out.println(sendField.getText()) ;
      					// Le texte est reçu
      					reciveField.setText(in.readLine()) ;
      				}
      				catch( IOException e )
      				{          
      					reciveField.setText("Erreur de transmission") ;
      				}
      				return true ;
      			}
      		}
      		if (evt.id == Event.WINDOW_DESTROY || "Client beenden".equals(evt.arg))
      		{
      			if (socket!= null)
      			{
      				try
      				{
      					socket.close() ;
      				}
      				catch(IOException e )
      				{
      				}
      			}
      			dispose() ;
      			return true ;
      		}
       
      		if (evt.id == Event.WINDOW_ICONIFY )
      		{
      			hide() ;
      			return true ;
      		}
       
      		return super.handleEvent(evt) ;
      	}
      

      [B] Sérialisation d'objet

      La sérialisation d'objet permet de récupérer toutes les informations d'un objet à un moment donné. L'objet peut être détruit. Lors de la récupération des information, un objet identique au premier est automatiquement créé. On peut se servir de ce procédé pour enregistrer des données sur disque dur.

      exemple : Pour être sérialisable, un objet doit implémenter les méthodes readObjet et writeObjet. La classe suivante implémente ces méthodes et de plus les méthodes loadFIle et saveFile. Ces deux méthodes ouvre un flux vers un fichier. Il suffit d'appeler la méthode readObjet(flux) pour lire l'objet du fichier. De même pour saveFile.

      import java.io.* ;
       
      public class Etude extends Object implements Serializable
      {
      	int annee1 ;
      	int annee2 ;
      	int annee3 ;
      	int annee4 ;
      	int annee5 ;
       
      	public Etude()
      	{
      		annee1 = 0 ;
      		annee2 = 0 ;
      		annee3 = 0 ;
      		annee4 = 0 ;
      		annee5 = 0 ;
      	}
         
      	private void writeObject(java.io.ObjectOutputStream stream)   
      	{
      		try
      		{
      			stream.writeInt(annee1) ;
      			stream.writeInt(annee2) ;
      			stream.writeInt(annee3) ;
      			stream.writeInt(annee4) ;
      			stream.writeInt(annee5) ;
      		}
      		catch(IOException e)
      		{
      			System.out.println(e) ;
      		}
      	}
      	private void readObject(java.io.ObjectInputStream stream)
      	{
      		try
      		{
      			annee1 = stream.readInt() ;
      			annee2 = stream.readInt() ;
      			annee3 = stream.readInt() ;
      			annee4 = stream.readInt() ;
      			annee5 = stream.readInt() ;
      		}
      		catch(IOException e)
      		{
      			System.out.println(e) ;
      		}
      	}
      	public void loadFile(String fileName)
      	{
      		try
      		{
      			FileInputStream fin = new FileInputStream(fileName) ;
      			ObjectInputStream stream = new ObjectInputStream(fin) ;
       
      			// Il suffit de lire l'objet pour le restituer
      			readObject(stream) ;
               
      			fin.close() ;
      		}
      		catch(FileNotFoundException e)
      		{
      		}
      		catch(IOException e)
      		{
      			System.err.println(e) ;
      		}
      	}
       
      	public void saveFile(String fileName)
      	{
      		try
      		{
      			FileOutputStream fout = new FileOutputStream(fileName) ;
      			ObjectOutputStream stream = new ObjectOutputStream(fout) ;
       
      			// L'objet est écrit le disque
      			writeObject(stream) ;
      			stream.flush() ;
       
      			fout.close() ;
      		}
      		catch(FileNotFoundException e)
      		{
      		}
      		catch(IOException e)
      		{
      			System.out.println(e) ;
      		}
      	}
      }
      

  3. Les classes de bases
  4. [C] La classe entreprise

    package utils ;
     
    //***************************************************************************
    //
    // @(#)Entreprise
    //
    // @author: Jean-Marc@Autexier
    //
    // @version: 17.09.1997
    //
    // purpose: La classe contient les informations d'une entreprise, ainsi que
    //          données nescéssaire à la simulation (anneeActuelle, etape, ...)
    //
    //***************************************************************************
     
    import java.io.* ;
    import utils.Bilan ;
    import utils.CompteResultat ;
     
    public class Entreprise extends Object implements Serializable
    {
    	private String nom = new String("")  ;
    	private String motDePasse = new String("") ; ;
    	private Bilan bilanActuell = new Bilan() ;
    	private Bilan bilanAnneePrecedentes[] = new Bilan[5];
    	private CompteResultat compteResultat = new CompteResultat() ;
    	private int anneeActuelle = 0 ;
    	private int etape = 0 ;
    	private boolean etudeDeMarche = false ;  // vrai, si effectuée
    	private int uniteProduction = 0 ;
    	private int uniteProdConstruction = 0 ;
     
    	// Constructeur par defaut
    	public Entreprise()
    	{}
     
    	// Accesseurs au attributs de la classe
    	public void setNom(String nom)
    	{
    		this.nom = nom ;
    	}
    	public String getNom()
    	{
    		return nom ;
    	}
     
    	// Methode permetant de serialiser l'objet entreprise
    	private void writeObject(java.io.ObjectOutputStream stream)
    	{
    		try
    		{
    			stream.defaultWriteObject() ;
    		}
    		catch(IOException e)
    		{
    			System.out.println(e) ;
    		}
    	}
     
    	private void readObject(java.io.ObjectInputStream stream)
    	{
    		try
    		{
    			stream.defaultReadObject() ;
    		}
    		catch(ClassNotFoundException e)
    		{
    			System.out.println(e) ;
    		}
    		catch(IOException e)
    	      	{
    			System.out.println(e) ;
    		}
    	}
     
    	// Sauvegarde d'une entreprise dans un fichier
    	public void writeFile(String fileName)
    	{
    		try
    		{
    			FileOutputStream fout = new FileOutputStream(fileName) ;
    			ObjectOutputStream p = new ObjectOutputStream(fout) ;
     
    			writeObject(p) ;
     
    			p.flush() ;
    			fout.close() ;
    		}
    		catch(IOException e)
    		{
    			System.out.println(e) ;
    		}
    	}
     
    	public void readFile(String fileName)
    	{
    		try
    		{
    			FileInputStream fin = new FileInputStream(fileName) ;
    			ObjectInputStream stream = new ObjectInputStream(fin) ;
     
    			readObject(stream) ;
     
    			fin.close() ;
    		}
    		catch(IOException e)
    		{
    			System.out.println(e) ;
    		}
    	}
    }
    

    [D] La classe bilan

    package utils ;
     
    //***************************************************************************
    // @(#)Bilan
    //
    // @author: Jean-Marc@Autexier
    //
    // @version: 17.09.1997
    //
    // purpose: bilan d'une entreprise, la classe implémente la sérialisation
    //          et peut être sérialiser par les méthode readObjet et writeObject
    //
    //***************************************************************************
     
    import java.io.* ;
     
    public class Bilan extends Object implements Serializable
    {
    	// L'actif du bilan
    	int immobilisationCorporelle ;       	// Actuelle
    	int immobilisationCorporelleCol1 ;	// Colonne 1
    	int immobilisationCorporelleCol2 ;	// Colonne 2
    	int immobilisationIncorporelle ;
    	int immobilisationCours ;
    	int stockProduitFini ;
    	int stockMatierePrem ;
    	int clients ;       // Argents du par les clients
    	int tresorie ;
     
    	// Le passif du bilan
    	int capital ;
    	int primeEmission ;
    	int reserves ;
    	int resultat ;
    	int emprunt ;
    	int decouvert ;
    	int fournisseur ;   // Argent due aux fournisseurs
     
    	// Constructeur et accesseurs aux attrivuts
    	public Bilan()
    	{
    		// ...
    	}
     
    	// Methode permetant de serialiser les objets
    	private void readObject(java.io.ObjectInputStream stream)
    	{
    		try
    		{
    			stream.defaultReadObject() ;
    		}
    		catch(IOException e)
    		{
    			System.out.println(e) ;
    		}
    		catch(ClassNotFoundException e)
    		{
    			System.out.println(e) ;
    		}
    	}
     
    	private void writeObject(java.io.ObjectOutputStream stream)
    	{
    		try
    		{
    			stream.defaultWriteObject() ;
    		}
    		catch(IOException e)
    		{
    			System.out.println(e) ;
    		}
    	}
    }
    

    [E] La classe Compte de résulat

    package utils ;
     
    //***************************************************************************
    // @(#)CompteResultat
    //
    // @author: Jean-Marc@Autexier
    //
    // @version: 17.09.1997
    //
    // purpose: Compte de résultat d'une entreprise, sérialisable par les méthodes
    //          readObject et writeObject
    //
    //***************************************************************************
     
    import java.io.* ;
     
    public class CompteResultat extends Object implements Serializable
    {
    	// La colonne ds chages
    	int matieres ;
    	int fraisPersonnel ;
    	int dotationAmortissement ;
    	int recherche ;
    	int publicite ;
    	int maintenance ;
    	int fraisFinanciers ;
    	int exploitation ;
    	int surOpGestion ;
    	int surOpCapital ;
    	int impotBenefice ;
    	int profit ;
     
    	// La colonne des produits
    	int ventes ;
    	int produitExceptionnels ;
    	int productionStockee ;
    	int perte ;
     
    	// Constructeur par defaut
    	public CompteResultat()
    	{
    		// ...
    	}
     
    	// Accesseurs
    	// ...
     
    	// Methode permetant de serialiser l'objet entreprise
    	private void writeObject(java.io.ObjectOutputStream stream)
    	{
    		try
    		{
    			stream.defaultWriteObject() ;
    		}
    		catch(IOException e)
    		{
    			System.out.println(e) ;
    		}
    	}
     
    	private void readObject(java.io.ObjectInputStream stream)
    	{
    		try
    		{
    			stream.defaultReadObject() ;
    		}
    		catch(IOException e)
    		{
    			System.out.println(e) ;
    		}
    		catch(ClassNotFoundException e)
    		{
    			System.out.println(e) ;
    		}
    	}
     
    	// Calcul du total des charges
    	public int charges()
    	{
    		return matieres + fraisPersonnel + dotationAmortissement + recherche
    			+ publicite + maintenance + fraisFinanciers + exploitation
    			+ surOpGestion + surOpCapital + impotBenefice + profit ;
    	}
     
    	// Calcul du total des produits
    	public int produits()
    	{
    		return ventes + produitExceptionnels + productionStockee + perte ;
    	}
     
       	// Remise à 0 du compte de résultat. Nescessaire au début de chaque année
    	public void RemiseA0()
    	{
    		setMatieres(0) ;
    		setFP(0) ;
    		setDA(0) ;
    		setRecherche(0) ;
    		setPub(0) ;
    		setMaintenance(0) ;
    		setFF(0) ;
    		setExploitation(0) ;
    		setSOG(0) ;
    		setSOC(0) ;
    		setIB(0) ;
    		setProfit(0) ;
    		setVentes(0) ;
    		setPE(0) ;
    		setPS(0) ;
    		setPerte(0) ;
    	}
    }
    

    [F] La classe ImageCanvas

    package utils ;
     
    //***************************************************************************
    //
    // @(#)ImageCanvas
    //
    // @author: Jean-Marc@Autexier
    //
    // @version: 17.09.1997
    //
    // purpose: héritée de Canvas, elle contient de plus une image et peut
    //                 recevoir des événements
    //
    //***************************************************************************
     
    import java.awt.* ;
     d
    // Image Canvas hérite de Canvas
    public class ImageCanvas extends Canvas
    {
    	// L'image contenu dans ImageCanvas
    	Image img ;
     
    	// Constructeur à partir d'une image
    	public ImageCanvas(Image img)
    	{
    		this.img = img ;
    		// On attend la fin du chargement de l'image
    		while (!prepareImage(img,null)) ;
    		// resize(img.getWidth(null), img.getHeight(null)) ;
    	}
    	// Affichage de l'image
    	public void paint(Graphics g)
    	{
    		g.drawImage(img,0,0,null) ;
    	}
    }
    

    [G] La classe TextCanvas

    package utils ;
     
    //***************************************************************************
    // @(#)TextCanvas
    //
    // @author: Jean-Marc@Autexier
    //
    // @version: 17.09.1997
    //
    // purpose: Champs texte pouvant recevoir des événements. Le texte passée en
    //          paramètres est décomposé en mots et affichée ligne par ligne
    //
    //***************************************************************************
     
    import java.awt.* ;
    import java.util.* ;
     
    // La classe TextCanvas hérite de Canvas
    public class TextCanvas extends Canvas
    {
    	protected String label ;    		// Le Label  à afficher (en une seul ligne)
    	protected int margin_width ;		// Largeur
    	protected int margin_height ;		// Hauteur
    	protected int alignment ;		// Allignement
    	public static final int LEFT = 0 , CENTER = 1, RIGHT=2 ;
    	protected int num_lines ;		// Nombre de ligne calculé
    	protected String[] lines ;		// Champs de lignes
    	protected int[] line_width = new int[10] ;
    	protected int max_width ;
    	protected int line_height ;
    	protected int line_ascent ;
    	protected boolean measured = false ;
     
    	// Constructeur à partir du String, de la largeur, de la hauteur
    	// et de l'alignement
    	public TextCanvas(String label, int margin_width,
    					int margin_height, int alignment)
    	{
    		this.label = label ;
    		this.margin_width = margin_width ;
    		this.margin_height = margin_height ;
    		this.alignment = alignment ;
    		newLabel() ;     // met le Label en plusieur lignes
    	}
     
    	public void setLabel(String label)
    	{
    		this.label = label ;
    		newLabel() ;
    		measured = false ;
    		repaint() ;
    	}
    	public void setFont(Font f)
    	{
    		super.setFont(f) ;
    		measured = false ;
    		repaint() ;
    	}
    	public void setForeground(Color c)
    	{
    		super.setForeground(c) ;
    		repaint() ;
    	}
    	public void setBackground(Color c)
    	{
    		super.setBackground(c) ;
    		repaint() ;
    	}
     
    	public void setAlignment(int a)
    	{
    		alignment = a ;
    		repaint() ;
    	}
    	public void setMarginWidth(int mw)
    	{
    		margin_width = mw ;
    		repaint() ;
    	}
    	public void setMarginHeight(int mh)
    	{
    		margin_height = mh ;
    		repaint() ;
    	}
    	public String getLabel() { return label; }
    	public int getAlignment() { return alignment; }
    	public int getMarginWidth() { return margin_width; }
    	public int getMarginHeight() { return margin_height; }
     
    	public Dimension preferredSize()
    	{
    		if (!measured) measure() ;
    		return new Dimension(max_width + 2 * margin_width,
    						num_lines*line_height+2*margin_height)  ;
    	}
    	public Dimension minimumSize() { return preferredSize() ; }
     
    	public void paint(Graphics g)
    	{
    		int x, y ;
    		Dimension size = this.size() ;
    		if (!measured) measure() ;
    		y = line_ascent + (size.height-num_lines*line_height)/2 ;
    		for (int i = 0 ; i < num_lines; i++, y+=line_height)
    		{
    			switch(alignment)
    			{
    				default:
    				case LEFT: x = margin_width;
    					break ;
    				case CENTER: x = (size.width-line_width[i])/2;
    					break ;
    				case RIGHT: x = size.width-margin_width-line_width[i]; 						break ;
    			}
    			g.drawString(lines[i],x,y) ;
    		}
    	}
    	protected synchronized void newLabel()
    	{
    		StringTokenizer t = new StringTokenizer(label + "\n") ;
    		num_lines = t.countTokens() ;
    		lines = new String[num_lines] ;
    		line_width = new int[num_lines] ;
    		for (int i = 0 ; i < num_lines; i++)
    		{
    			lines[i] = t.nextToken() ;
    		}
    	}
    	protected synchronized void measure()
    	{
    		FontMetrics fm = this.getToolkit().getFontMetrics(this.getFont()) ;
    		line_height = fm.getHeight() ;
    		line_ascent = fm.getAscent() ;
    		max_width = 0 ;
    		for ( int i = 0 ; i < num_lines; i++)
    		{
    			line_width[i] = fm.stringWidth(lines[i]) ;
    			if (line_width[i] > max_width)
    			{
    				max_width = line_width[i] ;
    			}
    		}
    		measured = true ;
    	}
    }
    

    [H] La classe Masque

    package utils ;
     
    //*********************************************************************
    //
    // @(#) Masque
    //
    // @version 17.09.1997
    //
    // @author Jean-Marc Autexier
    //
    // purpose : c'est la classe mère de tout les masques. Elle contient
    //           une référence sur la classe qui contient le masque. La méthode
    //           handle Event est abstraite ainsi que la méthode Actualiser.
    //
    //*********************************************************************
     
    import java.awt.* ;
    import utils.Retour ;
     
    // La classe Masque est abstraite. 
    abstract class Masque extends Panel
    {
    	private String  masqueNom ;		// Nom du masque
    	private Retour  parent ;			// Référence sur l'interface Retour
     
    	// Constructeur 
    	public Masque(String masqueNom, Retour parent)
    	{
    		super() ;
    		this.parent = parent ;
    		this.masqueNom = masqueNom ;
     
    		this.setLayout(null) ;
    		this.resize(515,400) ;
    		this.show() ;
    		this.resize(515,400) ;
    	}
    	
    	abstract public boolean handleEvent( Event evt) ;
    	abstract public void Actualiser() ;
     
    	// Les accesseurs servent aux enfants de la classe a accéder à
    	// l'interface Retour	
    	public String getMasqueNom()
    	{
    		return masqueNom ;
    	}
    	public Retour getMasqueParent()
    	{
    		return parent ;
    	}	
    }
    

    [I] Le masque Info

    package utils ;
     
    //***************************************************************************
    //
    // Program: @(#)MasqueInfo
    //
    // @author: Jean-Marc Autexier
    //
    // @version: 17.09.1997
    //
    // purpose: La classe MasqueInfo hérite de la classe abstraite Masque
    // Elle est un espace (Panel) de dimension 600,400. Elle doit implémenter
    // la méthode abstraite handleEvent de l'interface Retour et la méthode Actualiser
    //
    // return super.getMasqueParent().Retour(evt, super.getMasqueNom(),
    // 								"nom_objet") ;
    // permet de retourner à l'applet contenant MasqueInfo l'événement,
    // le nom de sa classe et l'objet sur lequel a eu lieu l'action
    //
    // Elle affiche 8 lignes de texte que l'on pourra changer par les méthodes
    // setLigne?(String) , ou ? est le numéro de la ligne
    // Le boutton Continuer renvoie l'info à l'applet
    //
    //***************************************************************************
     
    import java.awt.* ;
    import java.awt.Event.* ;
    import utils.Masque ;
    import utils.Retour ;
    import utils.TextCanvas ;
     
    public class MasqueInfo extends Masque
    {
    	private Label ligne1 ;
    	private Label ligne2 ;
    	private Label ligne3 ;
    	private Label ligne4 ;
    	private Label ligne5 ;
    	private Label ligne6 ;
    	private Label ligne7 ;
    	private Label ligne8 ;
    	private Button continuer ;
     
    	// Constructeur
    	public MasqueInfo(String nom, Retour parent)
    	{
    		super(nom, parent) ;
     
    		// Initialisation des attributs
    		ligne1 = new Label("", Label.CENTER) ;
    		ligne2 = new Label("", Label.CENTER) ;
    		ligne3 = new Label("", Label.CENTER) ;
    		ligne4 = new Label("", Label.CENTER) ;
    		ligne5 = new Label("", Label.CENTER) ;
    		ligne6 = new Label("", Label.CENTER) ;
    		ligne7 = new Label("", Label.CENTER) ;
    		ligne8 = new Label("", Label.CENTER) ;
     
     
    		// Placement des ligne dans le masque	
    		ligne1.reshape(50,80,400,20) ;
    		ligne2.reshape(50,100,400,20) ;
    		ligne3.reshape(50,120,400,20) ;
    		ligne4.reshape(50,140,400,20) ;
    		ligne5.reshape(50,160,400,20) ;
    		ligne6.reshape(50,180,400,20) ;
    		ligne7.reshape(50,200,400,20) ;
    		ligne8.reshape(50,220,400,20) ;
     
    		// Ajout des lignes au masque
    		add(ligne1) ;
    		add(ligne2) ;
    		add(ligne3) ;
    		add(ligne4) ;
    		add(ligne5) ;
    		add(ligne6) ;
    		add(ligne7) ;
    		add(ligne8) ;
     
    		// Construction du bouton 'Continuer'
    		continuer = new Button("Continuer") ;
    		continuer.reshape(200,260,70,30) ;
    		add(continuer) ;
     
    	}
     
    	// Accesseurs aux ligne
    	public void setLigne1(String ligne)
    	{
    		ligne1.setText(ligne) ;
    	}
    	// ...
     
    	// Gestion des événements du masque
    	public boolean handleEvent(Event evt)
    	{
    		if ( evt.target == continuer)
    			return super.getMasqueParent().Retour(evt,
    							super.getMasqueNom(), "continuer" ) ;
    		// A défaut
    		return super.getMasqueParent().Retour(evt,
    							super.getMasqueNom(),""); 
    	}
    	// Méthode de masque qu'il faut implémenter. Dans MasqueInfo,
    	// il n'y a rien a actualiser.
    	public void Actualiser()
    	{
    	}
    }
    

    [J] L'interface Retour

    package utils ;

     

    //***************************************************************************

    // @(#)Retour

    //

    // @author: Jean-Marc@Autexier

    //

    // @version: 17.09.1997

    //

    // purpose: L'interface met a disposition la méthode Retour, qui renvoie un

    // événement avec le nom de la classe et de l'objet ayant recu

    // l'événement

    //

    //***************************************************************************

     

    import java.awt.Event ;

     

    public interface Retour

    {

    public boolean Retour(Event evt, String windowName, String objetc) ;

    }

  5. L'interface utilisateur
  6. [K] L'écran principal

    [L] L'écran fonctionnement

    [M] L'écran du bilan

    [N] L'écran du compte de résultat

    [O] L'écran de décision principal

    [P] L'écran de décision

  7. Génération de documentation avec javadoc
  8. [Q] javadoc

    Pour l'interface "Retour", le générateur de documentation livre la page HTML suivante.

    e:\ javadoc -d doc -version -author *.java
    
    All Packages Class Hierarchy This Package Previous Next Index ------------------------------------------------------------------------ Interface utils.Retour public interface Retour ------------------------------------------------------------------------ Method Index Retour(Event, String, String) Methods Retour public abstract boolean Retour(Event evt, String windowName, String objetc) ------------------------------------------------------------------------ All Packages Class Hierarchy This Package Previous Next Index